Question

I'm developing an application for a museum, I need that application to be the only one the visitors can use.

The administrator of the museum has the possibility to quit this application, by a button, which will ask a password.

I already managed to override the return button. But the Home button is still active. I used this for my main activity:

<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.HOME" /> <category android:name="android.intent.category.DEFAULT" /> 

This will reload the main activity when the home button is pressed. But, when I try to close the application with my close button, the first instance of my application is closed but not the second one. The admin has to give the password again.

You can imagine if a user presses the home button 10 times, it will be very difficult for the admin to quit.

Is there a way to close all instances of my application at the same time?

Was it helpful?

Solution

when I try to close the application with my close button, the first instance of my application is closed but not the second one

there is only one instance of your Application, and two or more instances of your main Activity.

I guess you know the difference between activity and application, but I think it's important to mention it...

you can avoid adding to the activity stack additional instances of the same activity by providing in the manifest to the activity's element launch mode attribute.

for example, providing android:launchMode="singleInstance" according to the documentation, insures only one instance of your activity can be created. trying starting same activity on top of already existing one - will simply won't change anything in the activity stack, but just invoke the onNewIntent() activity callback on the already existing activity instance.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top