I am Launching an activity from the service. I am acquiring the partial wake lock before the service is started.
PowerManager mgr = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
lockStatic=mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, LOCK_NAME_STATIC);
lockStatic.setReferenceCounted(true);
I am starting the activity from service like this :
Intent intent = new Intent(mContext, NotificationActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
In My Activity class i am adding flags to display activity when screen locked like this :
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
/*Code to open a Dialog*/
}
When i Debug all the code works fine. Activity is called successfully. But if the screen is locked (There is no secure lock keyguard) the phone screen doesn't displays the activity. I have to manually unlock the phone and then can see the activity from running applications list.
As described here you must also set FLAG_FULLSCREEN for your activity