Android currentActivity not updated when resuming app using different action!

You must Login before you can answer or comment on any questions.

Hello,

I'm writing an app, which will require registration and email confirmation. In the confirmation email, there will be a link, which will open up the app again and fill out some forms.

In order to achieve this, I have to have two intent filters like this:

<intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <category android:name="android.intent.category.DEFAULT" />
                    <category android:name="android.intent.category.BROWSABLE" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="http" android:host="my.special.link"/>
        </intent-filter>
Now with this configuration, everything is fine when I START the app using my.special.link. I will be able to get the URL from intent within current activity, that I get using Ti.Android.currentActivity.

However, If I have the app running, suspend it using Home button and then click on my.special.link, app will start a new activity. The app is not resumed. It's kind of funny, because if I suspend the app started by clicking my.special.link, and will resume the app again I will get back to the one started with MAIN action. This means, that when the app is started with MAIN action, user will fill out some forms, will suspend the app and "resume" it using link, all of the forms are blank. Then, if user suspends the app and resumes it again, all of the forms are filled again. This is issue number one, however that's not all.

When the app is suspended and then "resumed" using my.special.link, I am not able to get the URL from intent. That's because Ti.Android.currentActivity does not point to the current activity, which was created using intent with the VIEW action [I probably confuse how this works, I am new to the whole intent/action/categories stuff]. Anyway, Ti.Android.currentActivity points to the activity app was started with, thus I can't get the URL. It's easy to confirm what I wrote by adding some listeners to the currentActivity. I've added pause/resume listeners and none of them are fired. However if I suspend the app again [this means the app was started from launcher, suspended using home button, my.special.link was clicked and again it was again suspended using home button] and then resume it, my event listeners are triggered.

This looks like a bug to me. Or two bugs. Or just my lack of understanding how it works. Anyway, I would like to ask, how to implement this scenario:

  1. User launches the app from launcher, fills out some forms.
  2. User suspends the app and clicks on a special.link, which opens the app again
  3. The link used to resume the app is parsed and form is updated with some new data.

Thanks, Krystian

— asked 9 months ago by Krystian Szczesny
3 Comments
  • I was able to resume my app using my.special.link to the same activity/window as was launched from the launcher. The solution to this problem is to add:

    android:launchMode="singleTask"
    to the activity node in your AndroidManifest.xml file.

    Unfortunately... I still can't get the URL my app was resumed with!

    — commented 9 months ago by Krystian Szczesny

  • I was able to get the URL in the event listener, however, event listener has to be in a special place - app.js file. If I move it somewhere else, it won't work. Unfortunately, it does not work if I specify the launchMode to singleTask nor singleInstance. So I gave up with it. For now it will simply launch another instance of my app, however I hope to solve it somehow [better than closing the app on pause].

    — commented 9 months ago by Krystian Szczesny

  • Do you have an actual sample to replicate what you are seeing?

    Do not forget to state both Ti SDK & OS versions.

    — commented 7 months ago by Eduardo Gomez

Your Answer

Think you can help? Login to answer this question!