Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to force the app to always start with Activity1 following use of the Home button?

Tags:

java

android

This app has multiple activities: eg: Activity1 -> Activity2 -> Activity3. If the app is opened after the Home button is used while in Activity2, the app returns to Activity2, but the desired functionality is for the app to always start with Activity1 from the launcher. Adding a finish() to the onStop() for Activity2 does cause app to start with Activity1 following use of the Home button, but then Activity3 causes the app to revert to Activity1 when it finishes, rather than Activity2, which is also undesirable. Is there a way to force the app to always start with Activity1 following use of the Home button?

public class Activity1 extends Activity {
    ...
    public void onCreate(Bundle savedInstanceState) {
        ...
        button1.setOnClickListener(new OnClickListener() {
            public void onClick(View arg0) {
                startActivity(Activity2);
                ...

public class Activity2 extends Activity {
    ...
    private boolean applyMenuChoice(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.menuItem1:
            startActivity(Activity3);
            ...
like image 694
jacknad Avatar asked Feb 02 '26 14:02

jacknad


1 Answers

You can configure this for your activity in your AndroidManifest.xml. I think the attribute you want is android:clearTaskOnLaunch.

You may want to check out what you can do with the activity element from the android dev guide.

like image 163
InverseFalcon Avatar answered Feb 05 '26 04:02

InverseFalcon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!