Search code examples
androidalarmmanagerwear-osandroid-pendingintent

The Interval until Android Wear app restart


I've developed an android wear app.
In this app, I want to be relaunched it after
the onStop() is called and close it.

So I added the following codes in the onStop().

Intent intent = new Intent(getIntent());
AlarmManager amgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
amgr.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 500, PendingIntent.getActivity(WatchActivity.this, 0, intent, 0));
android.os.Process.killProcess(Process.myPid());

These codes are succeeded to relaunch itself.
However, it takes about 5sec until my app starts again.

I want to restart within 1sec when the onStop() is called.

Are there any solution?


Solution

  • Starting from API 19, alarm delivery is inexact (see docs). Outside of that, why do you want to restart your app if it is stopped? That doesn't sound right ....