I have a BroadcastReceiver which should launch activity:
@Override
public void onReceive(Context context, Intent intent)
{
if (wakeLock == null)
{
PowerManager pm = (PowerManager) ApplicationScreen.instance.getApplicationContext()
.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
}
if (!wakeLock.isHeld())
{
wakeLock.acquire();
}
try
{
if (ApplicationScreen.instance != null) {
Intent dialogIntent = new Intent(context, MainScreen.class);
dialogIntent.addFlags(Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
ApplicationScreen.instance.startActivity(dialogIntent);
} else {
Intent dialogIntent = new Intent(context, MainScreen.class);
dialogIntent.addFlags(Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(dialogIntent);
}
} catch (NullPointerException e)
{
}
}
My MainScreen is:
@Override
public void onResume()
{
Log.e("TAG", "onResume");
super.onResume();
}
@Override
protected void onNewIntent(Intent intent)
{
super.onNewIntent(intent);
// getIntent() should always return the most recent
setIntent(intent);
Log.e("TAG", "onNewIntent");
}
onResume is never called after onNewIntent. I expect that, if device go to sleep, my BroadcastReceiver should wake it up and launch my MainScreen. Also should tell, that MainScreen extends ApplicationScreen. And ApplicationScreen extends Activity.
EDIT:
Device doesn't wake up. Screen stays off.
Aucun commentaire:
Enregistrer un commentaire