【发布时间】:2011-06-13 22:25:27
【问题描述】:
我正在寻找从不是 Activity 而是 Activity 类的包含对象的类中启动 Intent 的最佳方式。
例如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 的构造函数吗?还是有我不知道的更好方法?
【问题讨论】:
-
@J J:“我应该将 MainActivity 作为参数传递给 TestLauncher 的构造函数吗?” - 是的,或者只是将
this作为一次性传递给TestLauncher中用于启动活动的任何方法。
标签: android android-intent android-activity android-context