tags:

views:

287

answers:

1

I am creating a Lock Replacement application which obviously requires it to have an activity that starts the ACTION_SCREEN_ON is called. These are the portions of my code relevant to it:

public class StartupBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    Intent startupIntent = new Intent(context, Lockdown.class); // substitute with your launcher class
    startupIntent.addCategory(Intent.CATEGORY_HOME);
    startupIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(startupIntent);
}

}

Since ACTION_SCREEN_ON cannot be called from the Manifest I registered it dynamically in my main activity.

This is in my onCreate function of my main class (Lockdown)

IntentFilter filter = new IntentFilter (Intent.ACTION_SCREEN_ON);

BroadcastReceiver mReceiver = new StartupBroadcastReceiver();
    registerReceiver(mReceiver, filter);

Any help is highly appreciated. Thanks in advanced

A: 

I found the answer to this problem:

Adding android:launchMode="singleInstance" and <category android:name="android.intent.category.DEFAULT" /> to the manifest of your main activity. You also have to add this flag to the receiver startupIntent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);

Honzo