【问题标题】:Is it possible to send Intent after 5 minutes in android?是否可以在 android 中 5 分钟后发送 Intent?
【发布时间】:2016-04-11 11:57:33
【问题描述】:

我是安卓新手。请告诉我是否可以在 android 中 5 分钟、10 分钟后发送 Intent? 我该怎么做?

提前致谢。

【问题讨论】:

  • 发送 Intent 是指开始活动?
  • 是的,我想在 5 分钟后开始活动

标签: android


【解决方案1】:
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
  @Override
  public void run() {
    // Launch new Intent here
  }
}, ((1000 * 60) * 5)); // 5 minutes delay before execute run()

【讨论】:

  • 但是在run()中我可以写什么内容?
  • @user1371813 在run() 中,您可以输入您的代码来启动您的活动。
  • 意图意图 = new Intent(FirstActivity.this, NewActivity.class);开始活动(意图);
【解决方案2】:

请参阅下面的代码,它可能会对您有所帮助。使用此计时器 5 分钟。

 final Timer myt = new Timer();
    myt.schedule(new TimerTask() {

    @Override
    public void run() {
    // TODO Auto-generated method stub

    try {
      Intent intent= new Intent(currentActivity.this, new_activity.class);
      startActivity(intent);    
    } catch (Exception e) {
    // TODO: handle exception
    }

      myt.cancel();
    }
    }, 300000);

在调用意图计时器自动终止后的上述代码中。

【讨论】:

    【解决方案3】:

    嗯,如果操作系统决定在某个时候终止您的应用程序,这可能会变得很糟糕。如果您确实需要在 5 分钟后仍然通过该意图,您应该使用警报。看看this answer

    【讨论】:

      【解决方案4】:
      final Handler handler = new Handler();
      handler.postDelayed(new Runnable() {
      @Override
      public void run() {
       Intent intent= new Intent(youractivity.this, activitytostart5minuteslater.class);
       startActivity(intent);
      }
      }, ((1000 * 60) * 5));
      

      你读过cmets吗???

      【讨论】:

      • 事实上,我做到了。而你没有。 ;-) 你的编辑表明不是这样。
      • 他问我可以在里面写什么内容,我回答了。但你不会明白,没关系。 :)
      猜你喜欢
      • 1970-01-01
      • 2019-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多