How to get top activity name in Lollipop?
((ActivityManager)getSystemService(Context.ACTIVITY_SERVICE)).
getRunningTasks(1).get(0).topActivity
is not longer available for Lollipop:
* @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method
* is no longer available to third party
* applications: the introduction of document-centric recents means
* it can leak person information to the caller. For backwards compatibility,
* it will still retu rn a small subset of its data: at least the caller's
* own tasks, and possibly some other tasks
* such as home that are known to not be sensitive.
Calling from onResume in MyActivity
MyApplication.getInstance().saveCurentActivity(MyActivity.this)
saveCurentActivity(Activity a) {
this.activityName = a.getClass().getSimpleName();
}
is no good idea, because MyApplication can be destroyed on error (for example, NPE).