Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android中,如何从非活动类(没有任何扩展的类)调用活动类?_Android - Fatal编程技术网

在android中,如何从非活动类(没有任何扩展的类)调用活动类?

在android中,如何从非活动类(没有任何扩展的类)调用活动类?,android,Android,我想每隔一段时间从普通java类(不扩展任何内容)调用一个活动类来刷新Ui,是否可以从普通java类调用一个活动。我们可以使用intent和startactivity从另一个活动调用该活动。但我不确定是否从课堂上调用该活动 比如说 class example extends Activity { } class example2 extends Activity { // we can call like Intent intent = new Intent(this.exa

我想每隔一段时间从普通java类(不扩展任何内容)调用一个活动类来刷新Ui,是否可以从普通java类调用一个活动。我们可以使用intent和startactivity从另一个活动调用该活动。但我不确定是否从课堂上调用该活动

比如说

 class example extends Activity
    {

    }
class example2 extends Activity
{
// we can call like
Intent intent = new Intent(this.example2,example.class);
startActivity(intent);
}

    class test
    {
// How can i call example or example2 from here.
    }
谢谢


Lakshmanan

我用它来观看非活动类的YouTube视频-

Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(url));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // important step
context.startActivity(intent);
希望这对你有帮助

  • 萨利尔

您可以提供一个由创建对象的活动的上下文组成的参数。然后,您可以像在活动中一样使用上下文的方法

i、 g


它起作用了。我已经试过了。

@sail这对于查看url表单的非活动类很好。但我需要从非活动类转到ActivityClass。当我调用context.startactivityforresult时,是否给我错误?帮助我?
public class Foo {
  private Context context;

  public Foo(Context context) {
    this.context = context;
  }

  public void startActivity() {
   context.startActivity(/*your intent here*/);
  }
}
Intent intent12 = new Intent(context.getApplicationContext(), ImageClick.class);
context.startActivity(intent12);