Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android finish Activity and start another one

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?

like image 792
Android-Droid Avatar asked Sep 29 '11 15:09

Android-Droid


People also ask

How do I finish my current activity and start a new one?

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);

How fetch data from one activity to another activity in Android?

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()

How do I close an activity from another activity?

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..


1 Answers

Use

Intent intent = new Intent(SyncActivity.this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); 
like image 149
Zoleas Avatar answered Oct 11 '22 19:10

Zoleas