Determine which Activity is currently in

Determine which Activity is currently in

When the requirements change, the UI interface usually undergoes certain changes.

When we take over someone else's code, we need to quickly locate the corresponding Activity according to the page that needs to be modified.

Judging which Activity the current page corresponds to can be achieved in the following two ways.

BaseActivity implementation

First, create a new Kotlin class called BaseActivity.

"It's a Kotlin class, not an Activity, but the name is Activity, because it doesn't correspond to any layout"

open class BaseActivity :AppCompatActivity() {
    
    
    override fun onCreate(savedInstanceState: Bundle?) {
    
    
        super.onCreate(savedInstanceState)
        Log.d("BaseActivity", javaClass.simpleName)
    }
}

The points to note in the code are as follows:

  • Adding the open keyword means that the class can be inherited
  • Inherit AppCompatActivity
  • javaClass.simpleName indicates the name of the currently running example

Finally, change other activities from inheriting AppCompatActivity to inheriting BaseActivity.

In this way, when the Activity is onCreate(), the current Activity name will be printed.

MIUI power consumption monitoring

This function only supports mobile phones with MIUI installed for the time being.

Setting path: Settings → More Settings → Developer Options → Power Consumption Monitoring

After opening, you can see the current Activity name in the floating window provided by MIUI.

Guess you like

Origin blog.csdn.net/jiaweilovemingming/article/details/124640352