Bear with me since I am noob in android coding. I want to get the current activity object in order to get it's context in a plain class which is not an activity. Using ActivityManager we can get activity in form of ComponentName. But I want the actual activity object. Any idea how shall I achieve it? Thanks.
Update
Below is the function I've written to get current activity.
private static ComponentName getCurrentTopActivity() {
ActivityManager mActivityManager = (ActivityManager)MediWatchReceptionistApplication.getAppContext().getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> RunningTask = mActivityManager.getRunningTasks(1);
ActivityManager.RunningTaskInfo ar = RunningTask.get(0);
return ar.topActivity;
}
The class which contains above function looks like this:
public class MediWatchReceptionistWebApiWrapper {
..................
}
0 comments:
Post a Comment