0

There are 2-3 ways to use Intent to start New Activity.

Mostly, I am using

Intent openStartingPoint = new Intent("com.Example.Jeeten.Connection");
startActivity(openStartingPoint);

But sometimes, It does not work, It shows error Activity not found and in that case If I use

Intent openStartingPoint = new Intent(Connection.this, Hello.class);
startActivity(openStartingPoint);

then It works fine. What can be the issue with this ?

Jeeten Parmar
  • 5,568
  • 15
  • 62
  • 111

1 Answers1

0

When u make an activity, u have to register it in your AndroidManifest.xml file.

<activity
        android:name=".Connection"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.Example.Jeeten.CONNECTION" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

In the above code <activity android:name represents your activity class(Case sensitive),in your case its Connection and Hello.Next is <action android:name in this you specify by what name are you going to refer to the activity(its a good practice to put the last word all in uppercase CONNECTION). So make sure you have two such activities in your xml file.In case one of the activity is your starting point of your app,modify the <intent-filter> like this

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

<category android:name="android.intent.category.LAUNCHER" />
Deb
  • 2,431
  • 3
  • 18
  • 28