2

I created a sample application. In my application I have 4 Activitys and 1 BroadCastReciever that runs in background. Here I wrote there service for the purpose of when the user Unlock the screen, I run my application. Everything works fine except this:

When I run my application, I'm in my third activity. The user no longer interacts with screen so the device gets auto screen locked. Now I unlock the screen means, the application runs from the first activity. I need to run the application from the user's last interacted activity (for example, if the user interacted with the third activity, I need to show the third activity when the screen unlocks).

Cœur
  • 37,241
  • 25
  • 195
  • 267
Aerrow
  • 12,086
  • 10
  • 56
  • 90
  • 1
    Please upload the code as well. – Lucifer Sep 29 '12 at 03:16
  • See my answer below. You might need to differentiate how you got to first activity. Was it a onResume for example, a call to onStart() vs. onCreate(bundle) etc to know if it was on initial start of the app. – Code Droid Sep 29 '12 at 03:25
  • But for starters just store current activity name in SharedPreferences. Thats where it belongs. Then the only challenge is just to determine if your entering the MainActivity, was on a resume etc vs. the user navigating there. – Code Droid Sep 29 '12 at 03:26
  • @Aerrow you can refer this http://stackoverflow.com/questions/1450019/android-restore-last-viewed-activity – Vishal Vyas Sep 29 '12 at 03:35

2 Answers2

1

No problem, use SharedPreferences and store a currentActivityName. Update this when you enter a new Activity via onCreate or onStart(). This value will be preserved, even when the app shuts down. Once you detect your entry point you would just startActivity(activityName) once the app returns.

Code Droid
  • 10,344
  • 17
  • 72
  • 112
1

Do not finish the activity when you are moving from one activity to another activity and add WAKE_LOCK permissions in android manifest file

G M Ramesh
  • 3,420
  • 9
  • 37
  • 53