Domanda

I want to share url's from other apps to mine.

I am using this Phonegap Plugin to implement the intents:

https://github.com/chrisekelley/olutindo-app/tree/master/plugins/com.borismus.webintent

Intents are working, but everytime i share an intent from another app, a new instance of my app is launched, but i want to use one instance. If the app is already opened, it should be reinitialized and brought to front or restarted with the shared intent initialization.

I tryed android:launchMode="singleTop", but the same behavior occurs, app would be opened multiple times.

My manifest entry:

    <activity android:configChanges="orientation|keyboardHidden|screenSize"
        android:name=".StartActivity"
        android:label="@string/app_name"
        android:launchMode="singleTop" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW"></action>
            <category android:name="android.intent.category.DEFAULT"></category>
            <category android:name="android.intent.category.BROWSABLE"></category>
            <data android:mimeType="text/plain" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="text/plain" />
        </intent-filter>
    </activity>

These is no initialization in my MainActivity because the intents would be initialized from javascript with a own function (See PG plugin above).

Edit: I tryed to use android:launchMode="singleInstance". Now on every share request my app would be brought to top, but the intent is not initialized. How can i initialize the incoming intent request again with cordova, if the app is already started?

Thank you!

È stato utile?

Soluzione

I'm not sure how to workaround this. But i'm pretty sure that even if your code is launchMode="singleInstance" or singleTask, the OS will open an different Instance for each intent.action.

The only way to workaround i did find is creating a empty activity that calls your activity with a unique intent.action.

final Intent myIntent = new Intent(this,
MainActivity.class);
myIntent.setAction("android.intent.action.MAIN"); //myIntent.setAction(Intent.ACTION_MAIN);
startActivity(myIntent);

You can do a listening service. When you try to share the service get launched and it opens your activity if one intent.action aways.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top