Reputation: 627
I have an issue in my app. I'm creating a sort of improvised menu bar that has to be included in all activities in my app, I want to determine which activity is loaded currently so that via an intent the application will link to the Activity that is linked to a button:
public void graphAction()
{
Intent i = new Intent(this, GraphActivity.class );
this.startActivity(i);
}
Upvotes: 0
Views: 439
Reputation: 312
try below function to get the top activity name.
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();
}
Upvotes: 2
Reputation: 2563
You might want to consider using ActionbarSherlock (http://actionbarsherlock.com/) But I do not understand why you would want the currently active activity? If the graphAction is not in the activity but some custom object, just pass the activity there (or better: use a context object, Activities should not be passed around)
Upvotes: 0