999
999

Reputation: 83

startActivity not working

        public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
        //Toast.makeText(getApplicationContext(), "Position of selected item is: "+   position, Toast.LENGTH_LONG).show();

        if ("Abiding in Christ".equals(categories[position]))
                {startActivity(AbidingInChrist.class);}
        else if ("Abundant Living".equals(categories[position]))
                {startActivity(AbundantLiving.class);}
        else if ("Access to God".equals(categories[position]))
                {startActivity(AccessToGod.class);}
        else if ("Adoration of God".equals(categories[position]))
                {startActivity(AdorationOfGod.class);}
        else if ("Amazing Grace".equals(categories[position]))
                {startActivity(AmazingGrace.class);}

all of the startActivity s are underlined in red and want me to change to something or create a method same name. I did add all the activities to the manifest, but some of them didn't work:

  <activity android:name=".AbidingInChrist"</activity>
    <activity android:name=".AbundantLiving</activity>
    <activity android:name=".AccessToGod</activity>
    <activity android:name=".AdorationOfGod</activity>
    <activity android:name=".AmazingGrace</activity>
    <activity android:name=".AnsweredPrayer</activity>
    <activity android:name=".Atonement</activity>
    <activity android:name=".Attitudes</activity>
    <activity android:name=".Belief</activity>
    <activity android:name=".Blessing</activity>
    <activity android:name=".BloodOfJesus</activity>
    <activity android:name=".Boldness</activity>
    <activity android:name=".Brokenness</activity>
    <activity android:name=".Calling</activity>
    <activity android:name=".Comfort</activity>
    <activity android:name=".Commitment</activity>

It's hard to tell here, but every other one was in red saying that it was missing the android namespace prefix.

Appreciate ya'll!

Upvotes: 4

Views: 34766

Answers (4)

Melvin
Melvin

Reputation: 371

I know that this is an old question. Might be a bit irrelevant to the question details. But hopefully, might help someone who lands on this question for a similar issue.

In my case, "context.startActivity(...)" was supposed to launch an activity in a pendingIntent (when the app is in the background). It wasn't working because I had "Display over other apps" set as "Not allowed", in the application settings. Added the permission for the same and enabled it, to resolve the issue.

Upvotes: 0

Lanitka
Lanitka

Reputation: 932

Try to create Intent and start Activity passing this intent like

// Create intent to start new Activity
Intent intent = new Intent(context, YourActivity.class);
startActivity(intent);

Upvotes: 0

Carlos J
Carlos J

Reputation: 3045

The startActivity method takes an Intent as parameter. Yo are trying to pass a class and that's why you get the "red underline"

try this:

    if ("Abiding in Christ".equals(categories[position]))
            {startActivity(new Intent(this, AbidingInChrist.class));}
    else if ("Abundant Living".equals(categories[position]))
            {startActivity(new Intent(this, AbundantLiving.class));}
    else if ("Access to God".equals(categories[position]))
            {startActivity(new Intent(this, AccessToGod.class));}
    else if ("Adoration of God".equals(categories[position]))
            {startActivity(new Intent(this, AdorationOfGod.class));}
    else if ("Amazing Grace".equals(categories[position]))
            {startActivity(new Intent(this, AmazingGrace.class));}

Also in you manifest don't forget to close the quotes when you declare an activity

        <activity android:name=".AbidingInChrist"></activity>
        <activity android:name=".AbundantLiving"></activity>
        <activity android:name=".AccessToGod"></activity>

etc

Upvotes: -2

PedroHawk
PedroHawk

Reputation: 630

In your code try to use an intent to start activity:

   Intent i = new Intent(ACTUALACTIVITY.this, OTHERACTIVITY.class);
                startActivity(i);

and in your manifest put your activity full address (package.activity) like below:

<application>
(...)
            <activity
                android:name="packagename.YOURACTIVITY">
            </activity>
</application>

Upvotes: 11

Related Questions