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?
In the second activity, the back button at the top left can be used to go back to the 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.
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); } });
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