Android Question Application restarts when icon clicked

Status
Not open for further replies.

Facilauto Juan

Member
Licensed User
Longtime User
Hello there!

I have an application running in the device. If I press home key and then return to the app by pressing the multitask button, the app keeps running where I left it.

But, if I press home key and then I press the app icon the app restarts, even entering in main_activity_create.

What's happening? How can I avoid this restarting?

Thanks for the answers and your time.
 

Facilauto Juan

Member
Licensed User
Longtime User
Erel, the problem is that Android isn't killing the process. If I go to home and then go to the app using the multitask manager, It shows ok.
But, if I go to home and then click on the app icon, it restarts. It should have the same behavior , right?
 
Upvote 0

eps

Expert
Licensed User
Longtime User
I think you need to map out what is happening and then see if an issue is highlighted.

I think you are saying this :

Scenario A. App started, press Home Key, press Multitask Manager, re-enter App and it is still at the point that it was at.

Scenario B. App started, press Home Key, select App from icon, re-enter App but it starts all over again..

You will need to ensure that you have logged the Exit and Entry points for both scenarios and see if there is a difference. Just put some logging in place
to see what is going on - and of course be connected to the App itself. Are you seeing different messages in Logging when the App starts and stops for instance? Put logging in Activity Create, Activity Pause and Activity Restart, one of those will be the culprit and after a bit of investigation you usually see or realise why the App is acting as it is.

Are you able to trace through these two scenarios? Using the debugger? That might help. Maybe for some reason it isn't using the Activity Pause or Activity Restart Subs as you expect it to.. It's probably somewhere in one of those two that it's going differently.. You'll need to step through the code and/or put some breakpoints in place, but remember that for Activity Pause (I think) you won't be able to step through the code.

As mentioned by Erel I use Statemanager for my code, but this is mostly for when people use the Back Button as opposed to the Home Button as they work differently of course.
 
Upvote 0

Facilauto Juan

Member
Licensed User
Longtime User
Thanks for the responses.

The problem with that approach is that there could be global variables set in other previous activities. If I launch that activity directly, those variables could not be initialized.
 
Upvote 0

Avansys

Member
Licensed User
Longtime User
Yesterday, while I was testing my app, I realised that if I pressed the back button, the activity was the same when I went out of my app, so in the Main activity I used the FirstTime parameter for do a validate, if firsttime is true, then I use the Main code, else I finish the main activity and automatically the last activity starts again.

I don't know if this example is useful for you, but I hope it is!
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
"finish the main activity"???

if the main activity ends, should also finish the app.

Try this:

make a copy of the entire folder of the app.

Then delete the contents of activities, leaving the "skeleton" of the project and post it (probably just the Main and the activity started from Main)
 
Upvote 0

Avansys

Member
Licensed User
Longtime User
I have the following code in my Main Activity:

Sub Activity_Create(FirstTime As Boolean)

If FirstTime = False Then
Activity.Finish
Else

do something....

End If

End Sub

Sub Activity_Resume

End Sub

With this code, app never finish, and it works fine for me
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I have not an Activity.Finish in my Main Activity, but an ExitApplication in a sub CloseApp, called clicking a button.

The Main calls an Activity, it may in turn call another Activity. Each Activity has an Activity.Finish but does not have a button to jump to the Main (I was afraid that a call queue remain suspended).
 
Upvote 0
Status
Not open for further replies.
Top