我的应用中存在问题。我正在创建一种即兴菜单栏,必须包含在我的应用程序中的所有活动中,我想确定当前加载了哪个活动,以便通过意图将应用程序链接到链接到按钮的活动:
public void graphAction()
{
Intent i = new Intent(this, GraphActivity.class );
this.startActivity(i);
}
答案 0 :(得分:2)
尝试以下功能获取热门活动名称。
private String getTopActivityName() {
ActivityManager am = (ActivityManager)getApplicationContext().getSystemService(
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.getShortClassName();
}
答案 1 :(得分:0)
您可能需要考虑使用ActionbarSherlock(http://actionbarsherlock.com/) 但我不明白为什么你想要当前活跃的活动? 如果graphAction不在活动中但是在某个自定义对象中,只需在那里传递活动(或更好:使用上下文对象,不应传递活动)