繁体   English   中英

一段时间后重新启动android应用程序

[英]Restart android application after a time

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

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

但是,我认为您可以使用后台服务来实现该目的 ,该服务会在一段时间后启动Intent

恕我直言,最好的解决方案是警报管理器。 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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM