// Path: app/src/main/java/com/example/ddmeng/helloactivityandfragment/utils/TaskUtils.java
// public class TaskUtils {
// 
//     private static final String LOG_TAG = "Stack";
// 
//     public static String getCurrentTopActivityName(Context context) {
// 
//         ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
// 
//         //this method requires android.permission.GET_TASKS
//         List<ActivityManager.RunningTaskInfo> runningTasks = activityManager.getRunningTasks(2);
//         //this method was deprecated in API level 21
//         ComponentName topActivity = runningTasks.get(0).topActivity;
//         Log.i(LOG_TAG, "top Activity: " + topActivity.getShortClassName());
//         return topActivity.getShortClassName();
// 
//     }
// }


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;
import com.example.ddmeng.helloactivityandfragment.R;
import com.example.ddmeng.helloactivityandfragment.utils.TaskUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
        Intent intent = new Intent();
        intent.setClass(StandardActivity.this, SingleTopActivity.class);
        startActivity(intent);
    }

    @OnClick(R.id.launch_mode_start_single_task_button)
    void startSingleTaskActivity() {
        Log.i(LOG_TAG, "start single task button click");

        Intent intent = new Intent();
        intent.setClass(StandardActivity.this, SingleTaskActivity.class);
        startActivity(intent);
        // If the singleTask want to be in a different task, taskAffinity should be specified.
        // every time start a new singleTask activity from here, new task id++
    }

    @OnClick(R.id.launch_mode_start_single_instance_button)
    void startSingleInstanceActivity() {
        Log.i(LOG_TAG, "start single instance button click");
        Intent intent = new Intent();
        intent.setClass(StandardActivity.this, SingleInstanceActivity.class);
        startActivity(intent);
    }

    @OnClick(R.id.launch_mode_update_stack_info)
    void updateStackInfoButtonClick() {
        updateStackInfo();
    }

    private void updateStackInfo() {
// Path: app/src/main/java/com/example/ddmeng/helloactivityandfragment/utils/TaskUtils.java
// public class TaskUtils {
// 
//     private static final String LOG_TAG = "Stack";
// 
//     public static String getCurrentTopActivityName(Context context) {
// 
//         ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
// 
//         //this method requires android.permission.GET_TASKS
//         List<ActivityManager.RunningTaskInfo> runningTasks = activityManager.getRunningTasks(2);
//         //this method was deprecated in API level 21
//         ComponentName topActivity = runningTasks.get(0).topActivity;
//         Log.i(LOG_TAG, "top Activity: " + topActivity.getShortClassName());
//         return topActivity.getShortClassName();
// 
//     }
// }


// Path: app/src/main/java/com/example/ddmeng/helloactivityandfragment/launchmode/StandardActivity.java
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;
import com.example.ddmeng.helloactivityandfragment.R;
import com.example.ddmeng.helloactivityandfragment.utils.TaskUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

        Intent intent = new Intent();
        intent.setClass(StandardActivity.this, SingleTopActivity.class);
        startActivity(intent);
    }

    @OnClick(R.id.launch_mode_start_single_task_button)
    void startSingleTaskActivity() {
        Log.i(LOG_TAG, "start single task button click");

        Intent intent = new Intent();
        intent.setClass(StandardActivity.this, SingleTaskActivity.class);
        startActivity(intent);
        // If the singleTask want to be in a different task, taskAffinity should be specified.
        // every time start a new singleTask activity from here, new task id++
    }

    @OnClick(R.id.launch_mode_start_single_instance_button)
    void startSingleInstanceActivity() {
        Log.i(LOG_TAG, "start single instance button click");
        Intent intent = new Intent();
        intent.setClass(StandardActivity.this, SingleInstanceActivity.class);
        startActivity(intent);
    }

    @OnClick(R.id.launch_mode_update_stack_info)
    void updateStackInfoButtonClick() {
        updateStackInfo();
    }

    private void updateStackInfo() {
        String currentTopActivityName = TaskUtils.getCurrentTopActivityName(this);