Pratik
Pratik

Reputation: 30855

How to keep layout and its data

I need your help, I have 2 activities A and B where A is the main activity. Now B starts the activities from A using startActivityForResult() and from B when I finish it will go back to activity A.

This works fine but the actual purpose was like the Gmail application when you go back from B to A and then start activity B again from A, then A need to start activity with its last screen as i left it.

For example: from inbox->label->draft in gmail how to achieve this to keep data/layout as it is.

Upvotes: 0

Views: 114

Answers (2)

Pratik
Pratik

Reputation: 30855

How to switch Activity from 2 activities without losing its data and current state of data

Ok I have got solution that when every time start your application that time only activity will be created and view and put in stack so the next time you start again this activity just open from background so the activity will available in stack and just brought to front using start activity

From A to start ActivityB

Intent intent = new Intent(context,ActivityB.class);
intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);

Now for start ActivityA from ActivityB

Intent intent = new Intent(getInstance(), ActivityA.class);
intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);

It just brought front while activity start and put the current activity into background

Upvotes: 0

Nirali
Nirali

Reputation: 13805

Maybe android:launchMode="singleInstance" on activity A and B will get it done?

Upvotes: 1

Related Questions