5

Here is my scenarios:

  • The user opens the app and uses it => the app is in one of its screens
  • The user moves the app in the background by using the Home key
  • The user starts the browsing and browses on my site. Withing the website, certain links open the app
  • The user clicks on a link in the browser and the app is started, BUT even if activity is onPause, it is not being resumed, but started all over again, so the current session is being lost.

My main activity is using intent filter data so I've added:

  <activity android:name=".HomeActivity"
            <intent-filter>
                <data android:scheme="myprop" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
  </activity>

so when the user clicks a custom url in the browser, my app wakes up and starts the activity. So as I stated before, if my HomeActivity is onPause (meaning that the user already used it) is it possible to simply resume it (and of course parse the myprop parameters) while keeping the current user progress ?

Alin
  • 14,809
  • 40
  • 129
  • 218

1 Answers1

4

You need to define the launch mode of your activity to single instance. To do that, update your Activity in Android Manifest: android:launchMode="singleInstance"

After that, your existing activity will be opened and you will receive a callback for Activity.onNewIntent(Intent intent)

peter.bartos
  • 11,855
  • 3
  • 51
  • 62
  • I think this is the right approach, however I see a weird behavior:while opening the app when the user clicks on the browser, works fine, just as I wanted, when I start the app from the launcher, it does not resume as it did before... it just closes. I don't know how to explain it. If the app is not started at all and I start from Launcher icon it works for the first time. Second time I press the icon it just opens and closes and onCreate, onNewIntent or onResume does not get called... Just for the record, I have a SplashActivity which shows a image and then calls startActivity – Alin Oct 13 '14 at 13:02
  • Added question here; http://stackoverflow.com/questions/26341067/activity-not-being-started-from-launcher-when-using-singetintance – Alin Oct 13 '14 at 13:24