public class Myclass{
public static void Mymethod{
//i want to go to an Activity from here
}
}
答案 0 :(得分:1)
很容易!
按类型“活动”向静态类添加静态字段。
当你的活动创建时把这个指针放在其他类的静态字段中:
public class MyActivity extends Activity
{
public void onCreate()
{
Myclass.myactivity = this;
}
}
刚设置:Myclass.myActivity = this; 然后从Myclass.Mymethod
访问它public class Myclass{
public static Activity myActivity = null;
public static void Mymethod{
//i want to go to an "myActivity" from here
}
}
答案 1 :(得分:1)
很简单,您可以将Context对象从Activity类传递到Non Activity类,并使用它启动一个新的Activity。
Intent i=new Intent(contextObj, ClassName.class);
contextObj.startActivity(i);