Fragment aus Notification öffnen

  • Antworten:5
Uf Fe
  • Forum-Beiträge: 22

23.06.2014, 13:18:53 via Website

Servus,

ich habe folgendes Problem.
Und zwar möchte ich ein bestimmtes Fragment aus einer Notification öffnen.
Dies mache ich folgendermaßen:

Intent sintent = new Intent(context, Worker.class).setAction(Helper.ACTION_START_BY_NOTIFICATION);

PendingIntent pIntent = PendingIntent.getActivity(context, 0, sintent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

builder.setContentIntent(pIntent);

Jedoch wenn dann die Klasse Worker aufgerufen wird steht in getAction nicht meine definierte Konstante drin, sondern MAIN. Kann mir jemand sagen warum das der Fall ist?

Schon mal vielen Dank für die Hilfe.

Antworten
Gelöschter Account
  • Forum-Beiträge: 2.640

23.06.2014, 15:00:42 via App

Developer.android.com

Retrieve a PendingIntent that will start a new activity, like calling Context.startActivity(Intent). Note that the activity will be started outside of the context of an existing activity, so you must use the Intent.FLAG_ACTIVITY_NEW_TASK launch flag in the Intent.

Ich denke daran könnte es liegen.

Ich sammle gerne Namen in meinem Death Note.

Samsung Galaxy Note 2<3 -> Samsung Galaxy Note 3 <3

Antworten
Uf Fe
  • Forum-Beiträge: 22

23.06.2014, 15:24:37 via Website

Mit diesem Flag funktioniert es auch nicht.
Aber ich glaube, dass es an den von dir geposteten Problem liegt. Aber leider hilft mir das Flag nicht.

Antworten
Pascal P.
  • Admin
  • Forum-Beiträge: 11.286

23.06.2014, 15:44:07 via Website

Ich würde einfach das gewünschte Fragment als extra dem Intent übergeben.
Und das dann in der Activity auswerten und ggf. darauf reagieren bzw. das richtige Fragment öffnen
http://stackoverflow.com/questions/18037991/pendingintent-does-not-send-intent-extras

— geändert am 23.06.2014, 15:44:15

LG Pascal //It's not a bug, it's a feature. :) ;)

Antworten
Uf Fe
  • Forum-Beiträge: 22

23.06.2014, 15:58:06 via Website

Habe ich auch schon daran gedacht und auch schon ausprobiert.
Jedoch steht in getIntent().getExtras().getString("abc); immer null drin.

Antworten
Gelöschter Account
  • Forum-Beiträge: 2.640

23.06.2014, 16:05:53 via App

Bei einem Fragment muss man (glaube ich)

Fragment fragment;
fragment.setArgument (getIntent().getExtras().getString("name";));

machen

Ich sammle gerne Namen in meinem Death Note.

Samsung Galaxy Note 2<3 -> Samsung Galaxy Note 3 <3

Antworten