Ideor
Ideor

Reputation: 5

Get data from 2 successives activities

I want to get datas from a third activity to my first activity.

It looks like that :

Activity A (my Form) , I click on a button to generate a test -> Activity B ( choose a device to connect ) -> Activity C (generate datas) -> Activity A ( get the datas from Activity C)

I want to generate many tests on the same session , so I want to keep my datas.

Upvotes: 0

Views: 46

Answers (2)

Médéric
Médéric

Reputation: 948

You could use FLAG_ACTIVITY_CLEAR_TOP.

From documentation

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

For your example, if you have ActivityA, ActivityB, ActivityC, you could return to ActivityA from ActivityC with

Intent intent = new Intent(getContext(), ActivityA.class);
intent.setFlags(Activity.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtras(<DATA_NAME>, <DATA_VALUE>);

You activity will be launched with this new intent containing your data. Activity B and C will be finished.

Upvotes: 0

Naveen Rao
Naveen Rao

Reputation: 742

If the data is in the form of string or integer then you can use SharedPrefrences to store them . The data will remain stored until application is uninstalled or application data is cleared .You can store and get this data from any activity of your application . An Example is here if you need

Upvotes: 1

Related Questions