androidactivitygroup

Android reloading intent data on returning to activity from activity group


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 lose 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.


Solution

  • 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();