Transfer extra data to new activity but you don’t get in the new activity?!


If you want to transfer some extra data to the called activity you have to use the extra data within a intent. You can do it in this way:

Intent intent = new Intent(this, Activity2.class);
intent.putExtra(ActivityCategoryEdit.IDKEY, items.get(position).getID());

You just have to read the extra data within the onCreate function in called activity. Just like that:

id = getIntent().getIntExtra(IDKEY, -1);

That works as long the transfered value is a integer. But the type of the transfered ID is long in my case and if you try this way with a long value you just get the default value (-1) in the Activity2. This cost me some time to find out why. I have to use getLongExtra to get it work. A simple change was the solution … like always 😉

Here the code for the long value in Activity2. Activity1 don’t need to be changed.

id = getIntent().getLonExtra(IDKEY, -1);

Maybe this will help you.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.