如何获得当前的activity android
3个回答
2018-08-03 · 知道合伙人软件行家
关注
展开全部
2015-06-24
展开全部
getApplicationContext()
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> runningTasks = manager.getRunningTasks(1);
RunningTaskInfo cinfo = null;
if (runningTasks != null && runningTasks.size() > 0) {
cinfo = runningTasks.get(0);
}
ComponentName component = null;
if (cinfo != null) {
component = cinfo.topActivity;
}
String componentName = null;
if (component != null) {
componentName = component.getClassName();
}
//当前activityName
componentName;
List<RunningTaskInfo> runningTasks = manager.getRunningTasks(1);
RunningTaskInfo cinfo = null;
if (runningTasks != null && runningTasks.size() > 0) {
cinfo = runningTasks.get(0);
}
ComponentName component = null;
if (cinfo != null) {
component = cinfo.topActivity;
}
String componentName = null;
if (component != null) {
componentName = component.getClassName();
}
//当前activityName
componentName;
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询