0

I'm trying to call main activity using implicit intents. I give both action and category in intent but before starting the activity android system gives me a list of applications to select from for opening the activity.

Code snippet I am using to call the main activity follows:

protected void initiateActivity(int requestCode, String value, String oper) {
        Intent i = new Intent("android.intent.action.MAIN");
        i.addCategory("android.intent.category.LAUNCHER");
        i.putExtra("VALUE", value);
        i.putExtra("OPER", oper);
        startActivityForResult(i, requestCode);
    }

It seems to me that every app in system will be having same action, category combo, hence android is giving me that list of apps to select from. What changes can I make to my Main Activity so that this issue is not seen?

Kany
  • 45
  • 3
  • 9
  • why are you trying to do this? – dvs Feb 18 '15 at 18:37
  • just an experimental project! The thing is my app needs three activities and two(main activity and activity2) have similar layouts. So, instead of creating activity2, I am trying to re-use main activity only. – Kany Feb 18 '15 at 18:43

1 Answers1

0

Looks like you might need to separate out with intent-filters. It looks there is a good explanation in this post:

How can I start MAIN activity with the help of <intent-filter>?

Which recommends adding the filters such as these below or you will be calling the launcher:

<activity android:name=".MyActivity"
          android:configChanges="orientation|keyboardHidden"
          android:windowSoftInputMode="stateHidden"
          android:screenOrientation="portrait">
    <intent-filter>
          <action android:name="android.intent.action.MAIN"/>
          <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <intent-filter>
          <action android:name="com.package.name.MyAction"/>
          <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>

Community
  • 1
  • 1
JodiMiddleton
  • 310
  • 1
  • 8