On Android, anyway to identify when the app is resumed via device backbutton vs home screen app icon

Hi all!

I'm running into a tricky scenario with this business application I've built.

For some background to better assist you guys to assist me :smile: -

I've built an app that acts as a launcher for another app. Think of a webclip - you tap the icon on the home screen and it launches the intent of another app with some params to ensure it opens correctly. The way we wrote the code for this, any time the app is opened, it will automatically executes the code to launch the user into this other app - via both onStart and onResume functions respectively. We've already launched this app internally as an iOS app and are in testing phases for the Android version now. Since iOS doesn't have a back button on the device itself, this issue was only identified when we began testing Android.

The issues lies when the user is in the other app and taps the back button. It brings them from app where they do their business in -- back to the app which acts as a launcher. This results in a seemingly infinite loop for users. I'm looking to add some functionality where when the app is resumed via back-button press, it will just close the app all together rather than execute the code to launch the other app.

I hope this makes sense and I'd appreciate some input from the community on ways I could do this. It's a bit of a tricky one.

Thanks all!
-Mike

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    @MichaelAmato

    You can try to add a bool flag and init value false:

     bool flag = false;
    

    when you open the other app, set the flag to true

      flag = true;
    

    when you resume to the app, you can check the flag:

        protected override void OnResume()
        {
            base.OnResume();
            if (flag)// resume from  other app
            {
    
            }
            else {//resume from home screen app icon
    
            }
        }
    
Sign In or Register to comment.