[英]Resume Activity by service in Android
I want to develop a program which reminds word (english-turkish). 我想开发一个程序来提醒单词(英语-土耳其语)。 The things what I have to do below and please correct me if I'm wrong or bad way I'm using. 我在下面必须做的事情,如果我使用的方法有误或错误,请纠正我。
Main.java
class as an activity which includes a textview to show english word 创建和Main.java
类作为一个活动,其中包括一个显示英语单词的textview SharedPreferences
在“保存”按钮单击(在Prefs.java类内部)下编写一些代码,以将设置保存到SharedPreferences
MyService
name. 创建一个具有MyService
名称的服务。 SharedPreferences
inside the OnCreate method of MyService
. 从MyService
的OnCreate方法内的SharedPreferences
获取间隔。 New Word
use the service's function to connect and retrieve new word and show in TextView in Main activity 当按下New Word
使用服务的功能连接和检索新单词并在Main活动的TextView中显示 Ok
set Activity to Pause mode and show Home Screen 按下Ok
将活动设置为暂停模式并显示主屏幕 I have some difficulties to Resume Main activity and passing new word. 我在恢复主要活动和传递新单词方面遇到一些困难。
Do you know a way to bring front Main activity periodically while it is in resume state? 您是否知道一种在恢复状态下定期进行主要活动的方法?
There is no difference between starting activity and bringing them to foreground - read about activity lifecycle. 开始活动与将其置于前台之间没有什么区别-了解活动生命周期。 Service is ineffective if you want to use it as simple timer. 如果您想将其用作简单计时器,该服务将无效。 Much better approach is to use AlarmManager and scheduling next activity start. 更好的方法是使用AlarmManager并计划下一个活动开始。 Here you have an example. 这里有一个例子。 Then just override Activity.onStart() method, to fill all fields you want. 然后,只需重写Activity.onStart()方法即可填充所需的所有字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.