Android activity unique identifier

I need to get the unique identifier of an android activity instance. I would like to take the line that the activity operator writes to the log (for example: ActivityManager: activity pause time for HistoryRecord { 450495a0 ...}), but I do not know how to get it.

Does anyone know how I can get this string? Or is there another unique identifier for each instance of the action?

+5
source share
4 answers

Perhaps you can use Activity hashCode.

+7
source

every time in your project:

    MainActivity.class.hashCode(); 

In action

    this.hashCode();

You can even get hashCodeout of context

+1
source

, , .

Using the hashCode method for activity is not recommended if you want to keep it longer. As we all know, activities can be cleaned up by the operating system. This means that when they are recreated, they probably have a different hashCode than the previous instance. The solution for this (if you want to stay with an integer as id) could be getIntent (). Hashcode ()

+1
source

hashCode()in Activity, it returns the unique identifier of the android activity instance, but getTaskId()cannot return a unique value

0
source

All Articles