Re-launch my app if user killed it using the button Home

1,191 views
Skip to first unread message

Neylton Nascimento

unread,
Nov 16, 2019, 3:37:13 PM11/16/19
to MIT App Inventor Forum
Dears,

In case my AI2 APP inventor is running and the user clicks the button HOME, goes and close my app, can I somehow identify a flag which tells me that the app was killed by the user, then utilize this flag to re-launching my app? I do not want user to kill my app and if does so, I want to re-launch my app.

Thanks and BR,
Neylton

TimAI2

unread,
Nov 16, 2019, 3:44:25 PM11/16/19
to MIT App Inventor Forum
That would probably contravene the general workings of android, if possible
If a user wishes to close an app they will use the Home button/Back button
They can open it again using the Square button or via the Apps button on the home page

SteveJG

unread,
Nov 16, 2019, 3:50:42 PM11/16/19
to MIT App Inventor Forum
Sorry.  It is impossible to disable the Home button using App Inventor 2 or control the Home button function in any way.  App Inventor also does not support push functions that would allow you know when any app was killed by the user.

What you want to do might be possible using the professional Android Studio, but certainly not with App Inventor.

Chris Ward

unread,
Nov 16, 2019, 9:28:10 PM11/16/19
to MIT App Inventor Forum
Neylton

Your various recent posts all describe actions that would be related to the actions of a virus. Please share the reason why your App would be a good thing for your App Users.

BodyMindPower

unread,
Nov 17, 2019, 6:43:07 AM11/17/19
to MIT App Inventor Forum


But there might be a way / workaround:

1. Note: If the device Home button is pressed, the app is not killed, but in the background.
2. Try the following blocks to relaunch the app after the Home button is pressed:
    (You can also try to do this with a Notifier.)
3. Build the APK and try ...
    Maybe I'll attach the AIA (containing Taifun's Tools extension) later to this post.

Neylton Nascimento

unread,
Nov 18, 2019, 3:39:38 PM11/18/19
to MIT App Inventor Forum
Hi BodyMindPower,

It worked amazingly well in the 1st attempt. Very well done and Thanks a lot !

BR,
Neylton


Neylton Nascimento

unread,
Nov 22, 2019, 5:45:22 AM11/22/19
to MIT App Inventor Forum
Hi BodyMindPower,

You solution worked very well. However it takes around 5-6 seconds for my app to reopen the screen after user press the button home.

I want user to keep using my app and leave it only when he press the back button (no the home button), then while the 5 delay is in place the user has the opportunity to click and open anther app and then my app will be in background forever ( the screen of my app does not come back in case user open any another app e.g Whatsapp, Facebook etc, I tested it).  So, now, I would like a solution, either to make the screen of my app open fast without any delay to avoid user to open another app or if not solution for the delay issue, to freeze the mobile for the delay period to deny user to open other app until my app screen returns back to foreground. Any genial solution? Any comment you be much appreciated.

Thanks in advance.
Neylton

TimAI2

unread,
Nov 22, 2019, 6:01:52 AM11/22/19
to MIT App Inventor Forum
Don't think it is possible (we tried!)

You have still not told us why you want to do this?
Locking a user to your app is not a good thing to do, they should be able to exit....

BodyMindPower

unread,
Nov 22, 2019, 8:57:14 AM11/22/19
to MIT App Inventor Forum
Hi Neylton,

Yes, it takes a few seconds. If the user opens another app during this time, this app comes in the foreground. But the advantage is, if he closes this app again (by pressing the back button) your app comes in the forground.

We have already discussed your question and my solution intensively and extensively among the power users. Some feel that my solution is not appropriate / reasonable because it limits the basic features of Android.
Whether your users will love this? I'm not that sure.

And as Tim said, it would be really good (helpful) to know what the purpose is and what exactly should be achieved / prevented.

Regards,
Anke

@Tim "Locking a user to your app is not a good thing to do, they should be able to exit...."
The user can always exit the app by pressing the device back button.

Neylton Nascimento

unread,
Nov 29, 2019, 9:09:31 AM11/29/19
to MIT App Inventor Forum
Hi Anke,

Thanks a lot for your solution.

I just want to let the user leave my application when they press the back button, not Home button, that the reason of my posts. I am an amateur hobbyist engineer with an idea about app and and my focus is always to develop thing which will benefit the users. there is no any relation with virus or hacker or any other bad action which could go wrong direction or cause issues for the users.

If allow, I would prefer not share yet my app idea, until it is finalized and published if you kind allow me. Is that ok?

In my app I want user only leave if he press the back button and will exit only if he answers a questions, e.g. he will leave the app if a certain condition is met, e.g. a sensor is read and a given condition is match. That's it. so, if user press the Home button he will leav my app without answering the questions which will cause issue for my app. I just want to avoid it. 

You solution is great, however, still user can by pass my app because it takes few seconds for my APP comes back in foreground. I found very poor solution for it using notifier where a Notifier message from the size of the screen will be shown and will deny access to the other app icons because Notifier message is in foreground blocking user to click in Whatsapp app or Facebook for instance, then my app screen will come back after few seconds. I am sure you will have more elegant solution. Can you please tell me if there is better elegant solution for that?

Thanks in advance.
Neylton
Reply all
Reply to author
Forward
0 new messages