如何从 Activity 的包含类启动 Intent
我正在寻找从不是 Activity 而是 Activity 类的包含对象的类启动意图的最佳方法。
例如,活动类:
Class MainActivity extends ListActivty
{
...
TestLauncher tester;
}
以及我想要从中启动意图的类:
Class TestLauncher
{
public TestLauncher ()
{
//Code to create an intent needs a Context
//Intent i = new Intent(Context, class)
//Code to start activity needs to be called with an Activity
//Activity.StartActivity(i);
}
}
在架构上执行此操作的最佳方法是什么?我应该将 MainActivity
作为参数传递给 TestLauncher
的构造函数吗?还是有我不知道的更好的方法?
I'm looking for the best way to start an intent from a class that is not an Activity, but is a contained object of an Activity class.
For example the Activity Class:
Class MainActivity extends ListActivty
{
...
TestLauncher tester;
}
and the class that I want to start the intent from:
Class TestLauncher
{
public TestLauncher ()
{
//Code to create an intent needs a Context
//Intent i = new Intent(Context, class)
//Code to start activity needs to be called with an Activity
//Activity.StartActivity(i);
}
}
What is the best way to do this architecturally? Should I pass MainActivity
as a parameter to TestLauncher
's constructor? Or is there a better way that I am not aware of?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)