简体   繁体   中英

cannot call an activity from broadcastreceiver

I try to call my main activity from broadcast receiver

using this code:

        Intent i = new Intent();
        i.setClassName(MainActivity.class.getPackage().toString(),
                MainActivity.class.getName().toString());
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);

and I get this error:

12-06 19:17:19.776: E/AndroidRuntime(29271): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {package com.example.dowantcall/com.example.dowantcall.MainActivity}; have you declared this activity in your AndroidManifest.xml?

with manifest declaration:

<activity
    android:name="com.example.dowantcall.MainActivity" 
    android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen">
   <!--  android:theme="@style/Theme.Transparent"> -->
    <intent-filter>

    </intent-filter>
</activity>

edit

btw, I have tried:

    Intent i = new Intent();
    i.setClassName(MainActivity.class.getPackage().toString(),
            "MainActivity");
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(i);

and got the same error:

12-06 19:17:19.776: E/AndroidRuntime(29271): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {package com.example.dowantcall/MainActivity}; have you declared this activity in your AndroidManifest.xml?

what am I missing?

Try this

Intent i = new Intent(context, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);

Try this.

    Intent i = new Intent(context,MainActivity.class);

    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    context.startActivity(i);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM