如何从一个包含类的活动中开始的意图 [英] How to Start an Intent from a contained class of an Activity
本文介绍了如何从一个包含类的活动中开始的意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在寻找,开始从一类,它是不是一个活动的意图的最好方法,但一个Activity类的包含的对象。
例如活动类:
类MainActivity延伸ListActivty
{
...
TestLauncher测试仪;
}
和我想从开始的意图类:
类TestLauncher
{
公共TestLauncher()
{
// code创建一个意图需要一个上下文
//意图I =新的意图(背景下,类)
// code键启动活动需要被调用的活动
//Activity.StartActivity(i);
}
}
什么是做建筑的最好方法是什么?我应该通过 MainActivity
作为参数传递给 TestLauncher
的构造?还是有更好的方法,我不知道呢?
解决方案
类TestLauncher
{
公共TestLauncher(上下文C)
{
意图I =新的意图(C,YourActivity.class)
c.startActivity(ⅰ);
}
}
TestLauncher TS =新TestLauncher(getApplicationContext());
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?
解决方案
Class TestLauncher
{
public TestLauncher (Context c)
{
Intent i = new Intent(c, YourActivity.class)
c.startActivity(i);
}
}
TestLauncher ts=new TestLauncher(getApplicationContext());
这篇关于如何从一个包含类的活动中开始的意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文