App start by itseft on Android
-
08-03-2021 - |
質問
Are there any possibilities to make an app to restart by itself after 60 seconds of inactivity of the Android phone?
This is what I tried:
public class BootUpReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, SplashScreen.class);
PendingIntent pi = PendingIntent.getService(context, 0, i, 0);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.cancel(pi); // cancel any existing alarms
am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() +60000,
AlarmManager.INTERVAL_DAY, pi);
}
}
but is not working.
解決
yes use a Alarm manager to wake it up... you can use the alarm manager in the background service or something and then make the app to open.
他のヒント
you can also takes benefit of Async Class
http://labs.makemachine.net/2010/05/android-asynctask-example/
in onPostExecute you can do as u want.
所属していません StackOverflow