StartActivity in BroadcastReceiver - gelöst!

N

Nonsens

Gast
Hallo,

ich hab ein Problem. Hier den Code. Das hat vor kurzem noch funktioniert :angry: und nun bekomme ich eine Fehlermeldung. Anscheinend muss der Content das Flag FLAG_ACTIVITY_NEW_TASK haben. :confused2:

Code:
public class Receiver extends android.content.BroadcastReceiver {
    
    @Override
    public void onReceive(final Context context, final Intent intent) {
        try {
            String action = intent.getAction();
            if (action.endsWith(com.twofortyfouram.locale.TaskerIntent.ACTION_FIRE_SETTING)) {
                intent.setComponent(new ComponentName("de.blberger.launcher5", "de.blberger.launcher5.Launcher"));
                context.startActivity(intent);
            }
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }
}
Code:
W/System.err: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
W/System.err:     at android.app.ContextImpl.startActivity(ContextImpl.java:680)
W/System.err:     at android.app.ContextImpl.startActivity(ContextImpl.java:667)
W/System.err:     at android.content.ContextWrapper.startActivity(ContextWrapper.java:331)
W/System.err:     at android.content.ContextWrapper.startActivity(ContextWrapper.java:331)
W/System.err:     at de.blberger.launcher5.Receiver.onReceive(Receiver.java:16)
W/System.err:     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2810)
W/System.err:     at android.app.ActivityThread.access$1800(ActivityThread.java:150)
W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1484)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err:     at android.os.Looper.loop(Looper.java:168)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5845)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
 
Hallo,
sorry, dass ich nach langer vergeblicher suche diesen Thread aufgemacht habe. Danach hab ich es noch mal recherchiert und bin dann fündig geworden:

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Löste das Problem :biggrin:

Manchmal ist man halt ziemlich blind :ohmy:

Aber, wieso hat es dann zuvor ohne funktioniert :confused2: vielleicht doch zu viele Änderungen auf einmal gemacht :confused2:

Egal, nun tuts :biggrin:

Grüße
 
Zuletzt bearbeitet von einem Moderator:

Ähnliche Themen

Soljim
Antworten
5
Aufrufe
294
swa00
swa00
D
Antworten
23
Aufrufe
3.276
Data2006
D
OnkelLon
Antworten
13
Aufrufe
2.363
OnkelLon
OnkelLon
Zurück
Oben Unten