get Top Activity - Android android.app

Android examples for android.app:Activity Property

Description

get Top Activity

Demo Code

import android.app.Activity;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import java.util.List;

public class Main{

    public static ComponentName getTopActivity(Context context) {
        ActivityManager am = (ActivityManager) context
                .getSystemService(Activity.ACTIVITY_SERVICE);
        return am.getRunningTasks(1).get(0).topActivity;
    }/*from ww  w  .ja  v a 2  s  .c  om*/

}

Related Tutorials