Android Question Application does not close

chrjak

Active Member
Licensed User
Longtime User
Hey Community,

I have a GPS Sensor and I want that it becomes closed when you click on its notification. I've done that with a separate Activity called "StopGps", that only kills the service when it gets started and kills itself immediately after. That worked not very well but it worked often.

Now I changed it to the Main Module and I am using that Code before all other lines in Activity_Create and Activity_Resume:
B4X:
Dim StartingIntent As Intent = Activity.GetStartingIntent
If StartingIntent.HasExtra("Notification_Tag") Then
        If StartingIntent.GetExtra("Notification_Tag") = "StopGPS" Then
            StopService(GPS)
            GPSStopped ' A sub thats testing if the user had open the app when he clicked on notification and if its yes it saves the last values - It's not important to know for my StopService problem: It only writes some personal App settings into a file
            ExitApplication
            Activity.Finish   
End If
    End If

So in fact there are two killing code lines before all other Activity_Create Code and in _Resume another time... but somehow that does not work. When i click on the notification while the app is paused it opens the app after stopping the service nevertheless...

Sadly i am not allowed to publish the project...
But could you please help me anyway? I am also interested if there is a more easy way to kill the Service when clicking on its notification

Thank you so much
 
Last edited:

cirollo

Active Member
Licensed User
Longtime User
Hi! I've the same problem,

I have a button on the main page, it should close the app, this is the code:
B4X:
Sub Panel12_Click
'   Panel12.Color=Colors.RGB(255,215,0)
   Dim result As Int
   result = Msgbox2("Confermi uscita Programma?", nomeprog, "Si", "", "No",LoadBitmap (File.DirAssets, "warning_small.png"))
   If result = DialogResponse.Positive Then
     Activity.Finish
     ExitApplication
   End If
End Sub

but I still found my app open and the user has to do the close all command from the opened app view in android (double square button)
why?

cirollo
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
check the beginners guide and activities life-cycle tutorial

The App only gets truly closed when the OS itself releases the resources allocated to it.
 
Upvote 0

cirollo

Active Member
Licensed User
Longtime User
ok, I know this but it occurs also when I launch my app and then the main module starts
the button is on this activity, so no other activity is running, i finish the main activity and exit....there is no process running....
and the app is still open after ten minutes!
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Main "module" is also an Activity module, so even if you just start your app and then choose to close it, it will continue to live in the background, even after ten minutes... as long as the system doesn't run out of resources.
Take a deeper look at the starter service, it is useful to force a known entry point to the app when it comes back into foreground
 
Upvote 0

cirollo

Active Member
Licensed User
Longtime User
thanks cableguy,

so, I suppose this code should close the activity....

B4X:
If result = DialogResponse.Positive Then
  Activity.Finish
  ExitApplication
EndIf
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
If you have only a single Activity(Main) and have no other services running, then you could use the above code to end the process..
Although it would be recommended to only use Activity.Finish and better manage your app restart with a Starter Service .. as @Cableguy mentioned above.
 
Last edited:
Upvote 0

cirollo

Active Member
Licensed User
Longtime User
ok....i'll check, the problem is that the application is made with B4A 2.71....so I guess I have to port it to 5.80.....

:-(
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
It should be a simple copy/paste opération... Then time to mod it to your needs
 
Upvote 0
Top