Android reloading intent data on returning to activity from activity group
-
14-11-2019 - |
Question
I have multiple tabs and within them i have got an activity group for each. When i go from one tab to another then hit back i loose my intent data.
For example i start activity 1, pass object 1 to activity 2 via the activitygroup i then go to activity 3 passing object 1, however when i go back to activity 2 onCreate is never called and i cannot set my intent data if i want to go back to Activity 3.
Any help would be appreciated. Hope that makes sense.
Thanks
Jonathan
Solution
Actually I'm not really sure if I understand your question properly, but if you want to send data between activities you can use startActivitiForResult
or you can do something like this :
Intent intent = new Intent(Activity.this, Activiti2.class);
intent.putExtra("key", "value");
startActivity(intent);
in Activity2 :
String getData = getIntent().getStringExtra("key","default value");
// or getParent().getIntent().getStringExtra("key","default value"); depending on your situation.
and if you want to send data to Activity from Activity2 you can do something like this :
Intent intent = getParent().getIntent();
intent.putExtra("key", 0); // default sorting
getParent().setResult(RESULT_OK, intent);
finish();