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?
Use finish like this: Intent i = new Intent(Main_Menu. this, NextActivity. class); finish(); //Kill the activity from which you will go to next activity startActivity(i);
putExtra() method is used for send the data, data in key-value pair key is variable name and value can be Int, String, Float etc. getStringExtra() method is for getting the data(key) which is send by above method. according the data type of value there are other methods like getIntExtra(), getFloatExtra()
In Activity [A], on button click, I am calling Activity [B] without finishing Activity [A]. Now in Activity [B], there are two buttons, New and Modify. When the user clicks on modify then pop an activity [A] from the stack with all the options ticked..
Use
Intent intent = new Intent(SyncActivity.this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With