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.
 

ducphu

Active Member
Licensed User
Longtime User
Hi all, just manage to find this topic. I'm having the same issue. I thought my app has problem but I try using "Two activities" app in the tutorial. It also has same issue. So what is the conclusion? Many app, especially games, when you are playing.If you press HOME key and re-run the app again by clicking the icon, it still shows the game you were playing, not restart everything, how do they do it?
 
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime User
I've been having a similar problem, I tried Avansys's solution:
B4X:
Sub Activity_Create(FirstTime As Boolean)

If FirstTime = False Then
Activity.Finish
Else

do something....

End If

End Sub

But what I'm finding is that after I actually close my app with the back button
B4X:
Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed = True Then
        CallSub2(Unit_Comms, "KillUnit", "Main")
        Awake.ReleaseKeepAlive
    End If
End Sub

And try start the app from the icon again, it closes right away - FirstTime = False is being reported in the log window.
Is this because my service is still running?
 
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime User
Update. I added an ExitApplication to the main's Pause fuction, and now all appears to be working OK. On droid 6.0.1. Off to test on 5 and 4.4 now.
This seems to be the only way I can get it to work, is it OK to use ExitApplication?

B4X:
Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed = True Then
        CallSub2(Unit_Comms, "KillUnit", "Main")
        Awake.ReleaseKeepAlive
        ExitApplication
    End If
End Sub
 
Upvote 0
Status
Not open for further replies.
Top