Search code examples
androidandroid-intentandroid-activityonresume

How to start resume an activity with new information?


I have an activity A that contains several buttons. Clicking a button starts activity B. The intent used in startActivity(intent) contains info about what layout should be applied to activity B. For example clicking avtivity A's "wide" button will set the "wide" layout in Activity B.

This all works well the first time, but then when a different button is clicked in activity A, it just loads the same layout again.

Things I have tried are:

  • In activity B, moving setContentView() from onCreate to onResume. This had no effect, I suppose because the intent was still the same one from when the activity was first started.

  • in the manifest file adding " android:noHistory = "true" to activity B. This had the desired effect of loading the correct layout but "broke" the Back button's functionality.

Does anyone have any other ideas?

-


Solution

  • Try this, It might help you

    Intent intent = new Intent(MainActivity.this, TargetActivity.class);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    MainActivity.startActivity(intent);