Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I made a small app-block program segment and though it does not effect the rest of the code or the program it does not seem to trigger its actions when a user eneters another app, my emulator device is running API(18) and thus should not be effected by the recent API changes.

Code:

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    List < ActivityManager.RunningTaskInfo > tasks = activityManager.getRunningTasks(Integer.MAX_VALUE);


    ActivityManager.RunningTaskInfo ar = tasks.get(0);
    String activityOnTop = ar.topActivity.getClassName();
    Intent lockIntent = new Intent(this, LockScreen.class);
    lockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    ComponentName componentInfo = tasks.get(0).topActivity;
    if (!componentInfo.getPackageName().equals("com.example.epiclapser.noprocrastinate")) {
        this.startActivity(lockIntent);
    }

    setContentView(R.layout.activity_main_activity2);
}

Any help would be greatly appreciated.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900