Android activity is not displayed when the screen accelerates and the screen lock does not turn off

I have a BroadcastReceiver that launches an Activity . If the Activity starts when the screen is turned on, it is displayed, and everything is in order. However, on ICS and JB devices (I did not test GB or HC, but the problem does not exist with Froyo), if the Activity launched when the screen is off, the lockscreen is not disabled, and the activity is not disabled it displays when the phone is unlocked (or by unlocking manually, or using the code I entered for post Froyo devices).

Why, at least on ICS and JB devices, the screen lock does not turn off without the code mentioned below and why the activity is not displayed if the screen was turned off when the Activity started?

Here is the code:

In BroadcastReceiver :

 Intent alarmAlert = new Intent(context, AlarmGoneOffActivity.class); alarmAlert.putExtra(MyAlarmManager.ALARM_NUM_ID, alarm.ID); alarmAlert.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION); context.startActivity(alarmAlert); 

In AlarmGoneOffActivity.onCreate() :

 setContentView(R.layout.alarm_gone_off); final Window win = getWindow(); win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON, WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); } //so far all of my post froyo devices (ICS and JB no more GB) // don't bypass the lockscreen unless we use this if(Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) { KeyguardManager myKeyGuard = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE); KeyguardLock myLock = myKeyGuard.newKeyguardLock("ShabbosAlarm"); myLock.disableKeyguard(); } 

Edit: I would prefer not to use KeyguardLock.disableKeyguard() , because it locks the key lock until KeyguardLock.reenableKeyguard() , which is inconvenient. Any solutions?

Edit2: Now I can confirm that the problem exists only in ICS and above. Something has changed that interferes with locking the keypad lock? And even if it was, why my Activity not displayed when the screen is unlocked manually?

+7
source share
1 answer

Here is the basic implementation I used to do this. It works for my users from 2.3-4.3. You can build on it from here I'm sure. I created this very short activity, just to handle this event. You can use it as a helper class if necessary:

 import android.app.Activity; import android.os.Bundle; import android.view.WindowManager; public class BlankActivity extends Activity { @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON, WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); // Your code here - Or if it doesn't trigger, see below } @Override public void onAttachedToWindow() { // You may need to execute your code here } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { } } @Override public void onPause() { super.onPause(); finish(); } } 

And in the manifest:

  <activity android:name="com.your.package.BlankActivity" android:clearTaskOnLaunch="true" android:configChanges="keyboardHidden|orientation|screenSize" android:excludeFromRecents="true" android:launchMode="singleInstance" android:noHistory="true" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" > </activity> 

Unlike other related posts, the Translucent theme did not cause a problem, and there was no need to add a layout to the Activity.

Hope this works for you too.

+3
source

All Articles