0

I have an activity and a service running in different threads. It is a sound recorder for a night time.

The problem comes when the service crashes for any reason (we can't avoid that crash, as it comes from a external library) in the middle of the recording.

What I do, as a workaround, is to restart the activity when the Activity notices that the connection with the service has been lost. By recreating the activity, the service is recreated too.

The problem is that, it takes a lot of time (even 1 hour) between the call to

    bindService(RecorderService.newIntent(this), this, BIND_AUTO_CREATE);

and the callback

public void onServiceConnected(ComponentName name, IBinder service) {

I think this happens because the phone is in a kind of low-battery mode, as it is not used by the user in the middle of the night.

I call startService once the connection is done, as it is needed that the Activity and the Service is connected.

So the problem is that the record stops for that time, and I would need it to be running without interruptions. I could call startService once the activity is restating, but that would not ensure that the service would be connected at the time of another hypotethical crash.

Any idea about how to make the connction/start of the service faster?

Thanks in advance!

TT--
  • 2,956
  • 1
  • 27
  • 46
P. Pueyo
  • 23
  • 5

3 Answers3

1

If the problem is only the "low power mode" during the night I think you can aquire a WakeLock (https://developer.android.com/reference/android/os/PowerManager.WakeLock) to wake-up the CPU just before starting the Service or Activity. Don't forget to release the Lock when you've done ;)

emandt
  • 2,547
  • 2
  • 16
  • 20
0

I think there might be something retailed with memory issues and/or limits. Just create code to every 2 hours recorder stops, saves and start recording a new file. And problem should be solved.

At least if you sorted android.os.PowerManager.WakeLock

Ice Q
  • 13
  • 5
  • Thanks for the answer. I'm using a real device,and when It's recording, the phone is normally in AirPlane mode, it does not need an active internet connection. I don't think that is the soluition. – P. Pueyo Jul 16 '18 at 08:54
0

I have seen the similar issue with the services, there can be many reasons that the service stops such as battery, resources etc, I would start by checking the flags you used for the service, for example, it should be START_STICKY in first place, second thing I would recommend considering the AlaramManager in android which is for sure more reliable if you want something to run in background all the time.

Some useful links below:

Service Flags, AlarmManager

JNI_OnLoad
  • 5,472
  • 4
  • 35
  • 60
  • Thanks for the answer. The problem though is related to a external library. For some reason, it makes the service crash after a random time. It sends a signal 6-SIGABRT with code -6. – P. Pueyo Jul 16 '18 at 09:35