获取Activity的名字

class MainActivity3 : AppCompatActivity() {
    private  val TAG = "MainActivity3"
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main3)

        Log.d(TAG,"MainActivity name:"+ MainActivity::class.java.name)
        Log.d(TAG,"MainActivity simpleName:"+ MainActivity::class.java.simpleName)

        getActivityName(this)
    }

    private fun getActivityName(activity: Activity) {
        Log.d(TAG,"Activity localClassName:"+ activity.localClassName)
        Log.d(TAG,"Activity packageName:"+ activity.packageName)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            Log.d(TAG,"Android 10:Activity opPackageName:"+ activity.opPackageName)
        }
    }


}

你可能感兴趣的:(Android工具类,android)