I am new at developing Android .I have a question. How to pass object from one activity to another activity without using Intent.Can I do it by Interface ,if so how Could you please how can I hanle that
Asked
Active
Viewed 371 times
-1
-
biggest question: Why not using Intent? "Pass" suggests that one activity starts the other. So why not using the intent you have to create anyway to start the second activity? – WarrenFaith Dec 03 '14 at 10:19
-
Why not use putExtra on an intent? :O – cgew85 Dec 03 '14 at 10:21
-
My main purpose is that http://stackoverflow.com/questions/27173535/android-listview-item-edit-operation – MUMBUÇOĞLU Dec 03 '14 at 10:27
-
My main purpose is that http://stackoverflow.com/questions/27173535/android-listview-item-edit-operation I have 3 activity, MainActivity,ShowDetailAcivity,EditDetailAcivity MainActivity has listview,when I clicked item on listview,ShowDetailAcivity is launched.Component visibles on ShowDetailAcivity are false.it is just for view.Then I clicked option menu item(Edit) on ShowDetailAcivity,EditDetailAcivity is launched and the user can change the values of Course object.After that updated value of object will transfer to Listview to MainAcivity.I have just only ArrayList on MainAcivity – MUMBUÇOĞLU Dec 03 '14 at 10:36
4 Answers
2
I think you have 2 options
- In memory, save it to somewhere that all activities can reach, or make it static. This is not good idea though
- Save it to disk, and use it, such as shared preferences

Orhan Obut
- 8,756
- 5
- 32
- 42
2
- You can store it in SharedPreferences and then in another Activity restore it.
- You can store it in SQLite and then in another Activity restore it.
- You can use static links
- You can use service

Suvitruf - Andrei Apanasik
- 5,582
- 9
- 49
- 88
1
save data in a singleton class model and get the same object from another activity Create a class like this
public class SingletonModel {
private static SingletonModel instance;
public String textData = ""
public synchronized static SingletonModel getSingletonModel() {
if (instance == null) {
instance = new SingletonModel();
}
return instance;
}
private void SingletonModel(){}
}
From first activity do like this
SingletonModel.getSingletonModel().textData ="Your data goes here";
From second activity do like this
textView.setText(SingletonModel.getSingletonModel().textData);

Nitesh
- 3,868
- 1
- 20
- 26
-
also textData is private and can not be accessed through the `.` operator – Blackbelt Dec 03 '14 at 10:25