Issue with task managers / killers

bergapappa

Member
Licensed User
Longtime User
I have the most irritating last issue before publishing my first app.

From my visible "main" module I start a service with startserviceAt.
If Android would kill my app, I don't want the service to start.
Therefore I have added the following (a tip from the master himselfe):

Sub Service_Start (StartingIntent As Intent)

If main.AppIsAlive = False Then
CancelScheduledService("slumpljud")
StopService("slumpljud")
End If

When I did not succeed trying to get android to kill my app, I tried killing it with my built in Samsung task manager called Active applications. Works like a charm. The Scheduled Service is canelled.

But with any other task managers, I get a "Sorry -unexpected stop" when the service is starting.

Any Ideas what Im doing wrong?

I don't know how to get debugging info from my device, so please try to give some suggestions before ordering me to get debugging info :)

Pretty Please With Sugar On Top!

Regards

Bergapappa
 

bergapappa

Member
Licensed User
Longtime User
Ok, did not know there were apps for this. Tried one and it works very well, tnx for this tip.
Seem like there is a lot of logging going on, does this not slow down the android system and when are the logs cleared?
Tryed to export the log for my fault, got a text file that isn't very readable, but in the app I could read what has happend, so maybe I can explain it.

I get a:
"Fatal Exception: main" (main is my name for my activity thats been killed)
I get " unable to start service com."
I also get "FileNotFoundException"


In my service I'm going to play a mediaplayer, a mp3 sound. The thing is that I have the test if AppIsAlive before playing because I don't want to play it if my "main" is killed.

If main.AppIsAlive = False Then
CancelScheduledService("slumpljud")
StopService("slumpljud")
End If

I thougt maybe I put the AppIsAlive variable in the wrong module. If the main isn't alive, the service cannot get the value form the variable.
But this I tried to change having the variable in the service module, no change.
And " unable to start service com." indicates that my test is not even run???? wonder why?
Strange though that this works with the task killer I got from samsung.

Like I say I get a FileNotFound which I don't understand either. I use a variable declared in the service-module and & ".mp3" to put in the filename like this:
MediaPlayer2.Load(File.DirAssets,strSpin & ".mp3") (strSpin is the variable)

The thing is though, this works well in a normal situation, but not when my main has been killed. And I don't even want it to be played, therefore the test in the beginning.

Sorry that I cannot be more exact whit the logfiles and stuff. Will try to learn to handle this. Thankful though for any ideas.

regards

bergapappa
 
Last edited:
Upvote 0

bergapappa

Member
Licensed User
Longtime User
The logs

The text file I got from the log viewer was not very readable, but maybe you can if you open it in another logviewer.
Worth a try anyway
I could not isolate any logs, I get all or nothing.
The txt file is 657 kB, and it is to large for the forum, I'll send it per mail to [email protected].

What is the best app for reading logs in your opinion?
Maybe with good functions to isolate and export logs.

Search for "Soundbug", that is the apps name.
"main" is the main activity and "Slumpljud" is my service.

regards

bergapappa
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is the relevant message:
B4X:
Caused by: java.io.FileNotFoundException: .mp3
   at android.content.res.AssetManager.openAssetFd(Native Method)
   at android.content.res.AssetManager.openFd(AssetManager.java:330)
   at anywheresoftware.b4a.objects.MediaPlayerWrapper.Load(MediaPlayerWrapper.java:61)
   at com.bergapappa.soundbug.slumpljud._service_start(slumpljud.java:149)
You didn't post the code in Service_Start. The file name is empty for some reason.
 
Upvote 0

bergapappa

Member
Licensed User
Longtime User
In activity create i give the variable containing the "missing" part of the filename to the variable strSpin with: slumpljud.strSpin = "Alarm clock" (slumpljud is my service where the variable is declared)

Does not the service keep this value until ServiceStartAt next time?

And, why does it react on this when my initial IsAppAlive test should kill the service before going on with the mediaplayer and sounds?
B4X:
Sub Process_Globals
   Dim MediaPlayer2 As MediaPlayer
   Dim interv As Long
   Dim strSpin As String
   Dim AppIsAlive As Boolean
End Sub
Sub Service_Create
      MediaPlayer2.Initialize()
End Sub

Sub Service_Start (StartingIntent As Intent)

      If AppIsAlive = False Then
         CancelScheduledService("slumpljud")
         StopService("slumpljud")
      End If

   MediaPlayer2.Load(File.DirAssets,strSpin & ".mp3")


   MediaPlayer2.Play
   
   interv=Rnd(10,20)

   StartServiceAt("slumpljud", DateTime.Now + interv * 1000, True)

End Sub

Regards

bergapappa
 
Last edited by a moderator:
Upvote 0

bergapappa

Member
Licensed User
Longtime User
Hi Erel

Seems like it did the trick, TNX a lot.
Would love anexplanation what this "Return" does, I dont really get it?

First I thought it did not work, but then I realized I had moved the variable AppIsAlive to the Service module in all my testing. But when I moved it back you stuff worked like a charm.

Regards and many thanks

Bergapappa
 
Upvote 0

bergapappa

Member
Licensed User
Longtime User
Ok, what I did not understan was the fact that it continued to execute. Thought that stopping the service stopped the executing.

TnX a lot Erel
 
Upvote 0
Top