简体   繁体   English

如何获得使用意图打开的活动的参考?

[英]How do I get the reference of an activity I opened using intent?

Inside my MainActivity I open my SecondActivity 在我的MainActivity内部,打开SecondActivity

Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent);

How do I get the reference of this instance of SecondActivity inside my MainActivity? 如何在MainActivity中获取SecondActivity实例的引用?

//inside MainActivity
SecondActivity object = // make it equal to instance created above

Pass your a handler to the second one via trigger intent, like this: 通过触发器意图将处理程序传递给第二个处理程序,如下所示:

Intent intent = new Intent(this, SecondActivity.class);
intent.putExtra("Handler", handler);
startActivity(intent);

Then in your SecondActivity post message and data, maybe the instance of SecondActivity.this or another you like, to the handler. 然后在您的SecondActivity中将消息和数据(可能是SecondActivity.this或其他您喜欢的实例)发布到处理程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM