uzay95
uzay95

Reputation: 16622

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.

  1. Create and Main.java class as an activity which includes a textview to show english word
  2. Create another activity which shows Preferences to setup interval time to remind new words
  3. Write some code under the Save button click(inside the Prefs.java class) to save settings to SharedPreferences
  4. Inflate menu inside Main activity to show Preferences Activity
  5. Create a service with MyService name.
  6. Get interval from SharedPreferences inside the OnCreate method of MyService.
  7. Inside the OnStart method Run a Timer according to interval and continousley connect to web service to get a new word.
  8. Periodically bring to front Main activity(don't want to create every time from the begining, just want to resume activity) and show new word.
  9. When pressed New Word use the service's function to connect and retrieve new word and show in TextView in Main activity
  10. When pressed Ok set Activity to Pause mode and show Home Screen

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?

Upvotes: 0

Views: 2234

Answers (2)

piotrpo
piotrpo

Reputation: 12636

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. Here you have an example. Then just override Activity.onStart() method, to fill all fields you want.

Upvotes: 0

Thanasis Petsas
Thanasis Petsas

Reputation: 4448

Try to make an intent in the onResume() call with this flag: FLAG_ACTIVITY_REORDER_TO_FRONT which causes the launched activity to be brought to the front..

For more information click here.

Upvotes: 1

Related Questions