Android 技巧 - 取得当前活动的activity的class name / package name

来源:互联网 发布:php 二维数组去重复 编辑:程序博客网 时间:2024/05/21 10:20

<span style="font-family: Arial; background-color: rgb(255, 255, 255);">或许你的Service在运行的时候需要知道当前运行的进程是不是你的app,</span>

如果不是你的app在运行,那就给用户一个通知;否则不给。


<span style="font-size: 24px;"> </span><span style="font-size:18px;"> private String getCurrentActivityName(Context context) {    ActivityManager am = (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE);    // get the info from the currently running task    List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);    ComponentName componentInfo = taskInfo.get(0).topActivity;    return componentInfo.getClassName();  }</span>








0 0
原创粉丝点击