Reputation: 833
I have an activity Detail
that start a new activity List
via Intent
.
In List
I do stuff and then I need to pass some data back to Detail
.
The stack, before calling back from List
, should contain Detail
(on Pause) and List
(running).
The data I need to pass back are an ArrayList<MyObject>
, where MyObject
implements Parcelable
(and all its needed methods), so I can use
intent.putParcelableArrayListExtra("myList", myListOfParcelableObjects);
to send data via Intent.
The problem now is on the called activity, Detail
.
I've tried to catch the new intent via onNewIntent(Intent intent)
and onResume(..)
method, but the first (even using setIntent(intent)
) and the second doesn't get the new intent sent from List
and the data contained in intent.
How can I get the new intent in Detail
, manage new datas and "resume" Detail
as it was before calling List
?
Upvotes: 0
Views: 92
Reputation: 861
You can use Singleton class for storing common data. Hope it will help.
Upvotes: 0
Reputation: 2288
create a Singleton Manager save the Data there and use the data when needed.
public class DataManager {
private static DataManager instance = new DataManager();
private int mData;
private DataManager() {}
public static DataManager getInstance() {
return instance;
}
public void setData(int number) {
mData = number;
}
public int getData() {
return mData;
}
}
Activity A
DataManager manager = DataManager.getInstance();
manager.setData(1);
Activity B
DataManaget manager = DataManager.getInstance();
int data = manager.getData();
this is an Example. Hope it helps.
Upvotes: 1