get Base Activity - Android android.app

Android examples for android.app:Activity Property

Description

get Base Activity

Demo Code

import java.util.List;

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

public class Main{

    private static ComponentName getBaseActivity(Context context) {
        ActivityManager am = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        if (am == null) {
            return null;
        }//  w ww . j a v  a 2s  .co m
        List<RunningTaskInfo> info = am.getRunningTasks(1);
        if (info == null) {
            return null;
        }
        ComponentName activity = info.get(0).baseActivity;
        return activity;
    }

}

Related Tutorials