我想将调用活动与其他人进行比较,以了解哪一个称为当前活动。我试过了:
getCallingActivity().getClassName().toString().equals(MainActivity.class.toString())
它不起作用,除非在调用Intent中传递值,我们如何使用getCallingActivity()
或getCallingPackage()
来比较类?
答案 0 :(得分:6)
如果为其他活动的结果启动了活动,则可以按以下方式比较呼叫活动。
if (getCallingActivity().getClassName().equals(MainActivity.class.getName())) {
/* here the main activity is calling activity*/
}else{
/*other activity is calling activity*/
}