I’m trying to reach the current activity. The code below is from some other example and after editing has the correct name of current activity. But how do I get the actual instance from there?
ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
// get the info from the currently running task
List< ActivityManager.RunningTaskInfo > taskInfo = am.getRunningTasks(1);
ComponentName componentInfo = taskInfo.get(0).topActivity;
// this is the class-name
componentInfo.getClassName();
Thanx,
Marcus
You might want to store the instance of the Activity in myApplication. You can then update the currently active Activity everytime an Activity reaches onResume().
But as Rupert Rawnsley said, it would be better to put your methods elsewhere (Service, Singleton, Application).
Also if you plan to use the Activity in helperclasses, you will probably need a context only. In this case you can use the Applications context too in many cases. Otherwise you might want to think about restructuring your code.