Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About android:launchMode="singleInstance" compatibility

Tags:

android

I have used android:launchMode="singleInstance" in my application how compiled & run perfectly in android api 2.3.3 but when i have deployed my application in the android OS which based in api 4.0 ,the intent can't be launched in the background. What is the relation between android launchmode and the version of android api ?

like image 544
Sofien Rahmouni Avatar asked Aug 08 '26 09:08

Sofien Rahmouni


1 Answers

Finally, I have got it working. Following is the solution of my problem.

This is my BroadcastReceiver:

public class BroadcastReceive extends BroadcastReceiver{
    // Display an alert that we've received a message.    
    @Override 
    public void onReceive(Context context, Intent intent){
        Intent i = new Intent(context,CallActivity.class);
        i.setAction(Intent.ACTION_VIEW);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_FROM_BACKGROUND);
        context.startActivity(i);
    }
}

And in manifest.xml:

<activity
    android:name=".callActivity"
    android:label="@string/invite_activity_lbl"
    android:launchMode="singleTask">

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
    </intent-filter>
</activity>

It's compatible with API level 11 and more

like image 52
Sofien Rahmouni Avatar answered Aug 09 '26 22:08

Sofien Rahmouni



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!