Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.List;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.Context;

public class Main {

    public static boolean isTopApp(Context context) {
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningTaskInfo> TaskList = am.getRunningTasks(2);
        if (TaskList == null || TaskList.isEmpty()) {
            return false;
        }
        RunningTaskInfo rti = TaskList.get(0);
        String tmp = rti.topActivity.getPackageName();
        return tmp.equals(context.getPackageName());
    }
}