Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button to go back to MainActivity

Tags:

I want to create a button that would lead the user straight back to main activity which doesn't have the android name="com.example.example".
It has android.intent.etc...
How can I reference my button to go back to this activity?

like image 979
Moussa Avatar asked Jul 12 '12 21:07

Moussa


People also ask

How do I go back to previous activity?

In the second activity, the back button at the top left can be used to go back to the previous activity.

What code would you use to go back to a previous activity?

Android activities are stored in the activity stack. Going back to a previous activity could mean two things. You opened the new activity from another activity with startActivityForResult. In that case you can just call the finishActivity() function from your code and it'll take you back to the previous activity.


1 Answers

Lets say your main activity is called Main.java.

btnBack.setOnClickListener(new OnClickListener(){    private void onClick(){     Intent intent = new Intent(currentActivity.this, Main.class);     intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);        startActivity(intent);   } }); 
like image 95
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz Avatar answered Nov 07 '22 12:11

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz