get Top Activity Class Name - Android Activity

Android examples for Activity:Activity Feature

Description

get Top Activity Class Name

Demo Code


//package com.java2s;

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

public class Main {

    public static String getTopActivityClassName(Context context) {
        try {/*from w  ww  .  j  a va 2s .  c om*/
            ActivityManager am = (ActivityManager) context
                    .getSystemService(Context.ACTIVITY_SERVICE);
            ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
            return cn.getClassName();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related Tutorials