【问题标题】:Restart android application after a time一段时间后重新启动android应用程序
【发布时间】:2013-06-11 08:14:45
【问题描述】:

我需要在一段时间后重新启动我的 android。我的应用程序是带有图像的幻灯片。用户通过主页按钮或返回按钮关闭应用程序。我需要在一段时间后重新启动应用程序(丢失用户触摸设备几分钟后 - 就像屏幕保护程序一样)。是否有可能做到这一点? 谁能帮助我如何做到这一点?

【问题讨论】:

    标签: android screensaver application-restart


    【解决方案1】:

    我不确定这是个好主意。如果你的用户想退出你的应用,为什么要把它放在前面?

    但是,我认为您可以使用background service 来实现这一点,它会在一段时间后启动Intent

    【讨论】:

      【解决方案2】:

      恕我直言,最好的解决方案是警报管理器。 http://developer.android.com/reference/android/app/AlarmManager.html 示例:

      long nexttime = (new Date()).getTime() + 60L*60L*1000L;//one hour after.
      
          AlarmManager am=(AlarmManager)getSystemService(Activity.ALARM_SERVICE);
                  Intent intent = new Intent(this, MyService.class);
                  intent.putExtra(SomeExtras, false);//for instance
                  PendingIntent pi = PendingIntent.getService(this, 12345, intent, PendingIntent.FLAG_CANCEL_CURRENT);
                  am.set(AlarmManager.RTC,nexttime, pi);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-11-07
        • 2012-05-30
        • 1970-01-01
        • 1970-01-01
        • 2015-11-27
        • 1970-01-01
        • 2014-09-14
        相关资源
        最近更新 更多