Android获取当前运行程序栈中的Activity
来源:互联网 发布:紫猫编程学院 编辑:程序博客网 时间:2024/06/14 09:34
第一种:要方便一点(Service中无法使用)
String contextString = context.toString();
return contextString.substring(contextString.lastIndexOf(".") + 1, contextString.indexOf("@"));
}
private String getRunningActivityName(){
ActivityManager activityManager=(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
String runningActivity=activityManager.getRunningTasks(1).get(0).topActivity.getClassName();
return runningActivity;
}
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
RunningTaskInfo info = manager.getRunningTasks(1).get(0);String shortClassName = info.topActivity.getShortClassName(); //类名
String className = info.topActivity.getClassName(); //完整类名
String packageName = info.topActivity.getPackageName(); //包名
1.1.其他用法:
//get ActivityManager
ActivityManager activityManager=(ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
//one
// String className=activityManager.getRunningTasks(1).get(0).topActivity.getClassName();
//split one by one
List<RunningTaskInfo> list=activityManager.getRunningTasks(1);
RunningTaskInfo info=list.get(0);
ComponentName componentName=info.topActivity;
String activityName=componentName.getClassName();
if(activityName!=null){
//check DeviceControlActivity is open or die
if(activityName.equals("com.android.bluetooth.DeviceControlActivity")){
//refresh DeviceControlActivity
}else{
//start DeviceControlActivity
final Intent intent = new Intent(this, DeviceControlActivity.class);
intent.setFlags(intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_NAME, device.getName());
intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_ADDRESS, device.getAddress());
startActivity(intent);
}
}else{
//
}
转载至:http://blog.csdn.net/wk1063645973/article/details/48860103 (若侵犯到博主权益,联系本人,定会删除)
- Android获取当前运行程序栈中的Activity
- 获取当前程序,activity是否在运行
- android 获取当前正在运行的activity
- android 如何获取当前运行的activity
- 获取当前运行的activity
- android获取当前运行Activity名字的方法
- Android通过ADB命令获取当前运行的Activity
- android获取当前运行Activity名字的方法
- 获取当前程序是否运行
- 获取当前运行程序路径
- 获取当前程序运行路径
- Android获取当前激活Activity
- android 获取当前的activity
- 获取当前正在运行的Activity
- 获取当前界面正在当前运行的Activity的名字
- android获取当前运行Activity的名字(解决避免及时聊天再出现通知)
- android 获取当前运行的activity(待整理测试····)
- Android 判断应用前后台运行状态并获取当前 Activity 实例
- 关于XML文档的xmlns、xmlns:xsi和xsi:schemaLocation
- 【队内胡策 10.30】T1
- Java之位运算
- 微信小程序如何使用template
- Fatal signal 11 (SIGSEGV), code 2, fault addr 0x9ff811c0 in tid 28902
- Android获取当前运行程序栈中的Activity
- tar 解压缩命令
- LeetCode : Minimum Number of Arrows to Burst Balloons
- tomcat窗口修改显示名字
- java实现excel的导入和导出
- HQ嵌入式学习路径
- meterpreter 命令
- Python爬虫入门:综述
- 病假单丢了医院给补吗