receiver
activity 실행
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
이미 실행중인 activity resume할때
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(i);
tip) 실행중인 task 확인하기.
ActivityManager am = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(10);
ComponentName componentInfo = null;
for (RunningTaskInfo runningTaskInfo : taskInfo) {
if (runningTaskInfo.topActivity.getPackageName().equals(context.getPackageName())) {
componentInfo = runningTaskInfo.topActivity;
Log.v(TAG, "packageName : " + componentInfo.getPackageName());
Log.v(TAG, "className : " + componentInfo.getClassName());
if (componentInfo.getClassName().equals("com.example.lockedscreen.MainActivity")){
Log.v(TAG, "++ FLAG_ACTIVITY_CLEAR_TOP ++");
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(i);
return;
}
}
}