Android 每隔一段时间自动启动应用程序
我开发了一个应用程序,我每天都需要它。但有时它只是崩溃。我正在考虑创建一个有间隔的自动启动,例如,每 30 分钟,应用程序启动一次,但我找不到方法。有什么想法吗?提前致谢。 我的应用程序是一个活动,就像服务器一样,仅供我个人使用。
I have developed an app and I need it the hole day up. But somethimes it just crash. I was thinking on creating an autostart with an interval, for ex, every 30 min, the app gets up, but I can't find the way. Any ideas? thanks in advance.
My app is an Activity, like a server, just to my personal use.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您应该真正弄清楚应用程序崩溃的原因并首先修复它。其次,您确定您的应用程序崩溃了吗?它可能会被操作系统阻止以尝试节省内存。
您的应用程序是“活动”吗?您希望它在后台运行吗?如果是这样,您应该使用服务。 http://developer.android.com/guide/topics/fundamentals/services.html 活动实际上仅在屏幕上可见时才运行。任何在没有可见 Activity 的情况下完成的工作都应该在服务中完成。
First you should really figure out why your application is crashing and fix that first. Second are you sure your application is crashing? It might be getting stopped by the OS in an attempt to save memory.
Is your app an Activity, and do you want it to run in the background? If so you should use a service instead. http://developer.android.com/guide/topics/fundamentals/services.html Activities are really only meant to be running when they are visible on the screen. Any work that is done without a visible Activity should be done in a service.
请参阅
AlarmManager
来调用应用程序或服务,并参阅PowerManager
来保持手机唤醒(否则您的应用程序将因睡眠模式而无法运行)。顺便说一句,我希望您这样做只是为了测试,因为这会很快耗尽电池,没有人愿意运行这样的应用程序。
See
AlarmManager
to invoke the app or service andPowerManager
to keep the phone awake (or else you app wont run due to sleep mode).Btw, I hope you are dooing this just for test, as this would drain the battery quickly and no one would want to run an app like this.