KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have followed this link and successfully made singleton class in Android. http://www.devahead.com/blog/2011/06/extending-the-android-application-class-and-dealing-with-singleton/ Problem is that i want a single object. like i have Activity A and Activity B. In Activity A I access the object from Singleton class . I use the object and made some changes to it. When I move to Activity B and access the object from Singleton Class it gave me the initialized object and does not keep the changes which i have made in Activity A. Is there any other way to save the changing? Please help me Experts. This is MainActivity public class MainActivity extends Activity { protected MyApplication app; private OnClickListener btn2=new OnClickListener() { @Override public void onClick(View arg0) { Intent intent=new Intent(MainActivity.this,NextActivity.class); startActivity(intent); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Get the application instance app = (MyApplication)getApplication(); // Call a custom application method app.customAppMethod(); // Call a custom method in MySingleton Singleton.getInstance().customSingletonMethod(); Singleton.getInstance(); // Read the value of a variable in MySingleton String singletonVar = Singleton.customVar; Log.d("Test",singletonVar); singletonVar="World"; Log.d("Test",singletonVar); Button btn=(Button)findViewById(R.id.button1); btn.setOnClickListener(btn2); } } This is NextActivity <pr
Tags (comma-separated)
Save Edits
Cancel