除了在 Intent
中将类名称作为 Extra
传递之外,是否有办法知道哪个 Activity 类启动了另一个 Activity 类?
当我们在onCreate
中执行new Intent(this, SomeOtherActivity.class)
时是否可以获取this
的名称SomeOtherActivity
?
最佳答案
创建一个实例并向 Intent 添加额外内容:
Intent i = new Intent(this, SomeOtherActivity.class)
i.putExtra("ACTIVITY_NAME", this.getClass().getName());
检索它:
Bundle extras = getIntent().getExtras();
String activityName = extras.getString("STRING_I_NEED");
关于java - 我们能知道启动当前 Activity 的类名吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32266301/