I want to write some kind of background-live application for sports Internet services ... I would like my application to constantly call TIME_TICK.
Btw: I also tried using AlarmManager, but the problem is the same.
But now my problem ...
I use the receiver with the Service for part of the execution. The recipient is called every minute correctly after registration. But every night the service stops and will never be called again.
In Android 2.x everything works fine, but Android 4.x will stop the receiver every day ... Is it possible to save the application on Android 4.x?
Reveiver is registered in my main activity:
registerReceiver(new MyReceiver(), new IntentFilter(Intent.ACTION_TIME_TICK));
Manifest Records:
<service android:name="de.pepdev.MyService" />
<receiver android:name="de.pepdev.MyReceiver">
<intent-filter>
<action android:name="android.intent.action.TIME_TICK" />
</intent-filter>
</receiver>
Receiver class:
public class MyReceiver extends BroadcastReceiver
{
public static long nextExecTime = 0;
public static Calendar currentTime = Calendar.getInstance();
@Override
public void onReceive(Context context, Intent intent)
{
currentTime = Calendar.getInstance();
if(nextExecTime <= currentTime.getTimeInMillis())
{
Intent service = new Intent(context, MyService.class);
context.startService(service);
}
}
}
source