I'm curious about one thing. How can I finish my current activity and start another one.
Example :
MainActivity
--(starts)--> LoginActivity
--(if success, starts)--> SyncActivity
--(if success start)--> MainActivity (with updated data).
So I want when SyncActivity
starts MainActivity
after succesfull sync and if I press back button not to return to SyncActivity
or any other activity opened before SynActivity
.
I've tried with this code :
Intent intent = new Intent(Synchronization.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
this.finish();
but it's not working properly. Any ideas how to get the things to work properly?
Judging from your OP, I'm not sure if you absolutely must initialize your mainActivity twice..
Android is designed so that an app is never really closed by the user. Concentrate on overriding the android lifecycle methods such as OnResume and OnPause to save UI data, etc.
Hence, you don't need to explicitly
finish()
the main activity (and really shouldn't). To receive login or sync data from the previous activities, just override theOnActivityResult()
method. However, to do this you must start the activity usingstartActivityForResult(intent)
. So for each activity you should do this:Main activity:
to start login:
to recieve login info:
Login activity:
to start sync:
to recieve info and return to Main:
This might not all compile, but hopefully you get the idea.
Use