Reputation: 1519
I'm showing an activity in lockscreen from a background service while the device is locked when the user is within a certain area (GPS obtained).
The activity has this code:
protected void onCreate(Bundle savedInstanceState) {
...
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
...
}
And it is being called from the service like this:
if (inArea){
PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
if (pm.isScreenOn()==false){
Intent wakeIntent = new Intent(mContext, mClass);
wakeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(wakeIntent);
}
}
When the user exits the area the activity should no longer be seen in lockscreen. But I cant get that.
I tried this when the user's GPS is outside the area:
if (!inArea){
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
}
But the activity remains present in the lockscreen.
Any suggestion on how to achieve this?
Upvotes: 0
Views: 194
Reputation: 93569
Have the service broadcast when the user exits the are. Have the activity register a broadcast receiver for that broadcast. If it receives that broadcast, have it finish() itself.
Or a dozen variations on this- they all boil down to have the application get informed when its no longer in the area and kill itself.
Upvotes: 2