Absichtserklärung

Meine Android-app wird immer aufgerufen, durch eine Absicht, die Weitergabe von Informationen (pendingintent in der Statusleiste).

Wenn ich drücken Sie die home-Taste und öffnen Sie die app, indem Sie die home-Taste ruft es die Absicht wieder, und die gleichen extras sind immer noch da.

    @Override
    public void onSaveInstanceState(Bundle savedInstanceState) {
      super.onSaveInstanceState(savedInstanceState);
    }
    @Override
    public void onRestoreInstanceState(Bundle savedInstanceState) {
      super.onRestoreInstanceState(savedInstanceState);
    }

dies ist der code, der läuft nicht wie sein soll

    String imgUrl;
    Bundle extras = this.getIntent().getExtras();


    if(extras != null){
        imgUrl = extras.getString("imgUrl");
        if( !imgUrl.equals(textView01.getText().toString()) ){

            imageView.setImageDrawable( getImageFromUrl( imgUrl ) );
            layout1.setVisibility(0);
            textView01.setText(imgUrl);//textview to hold the url

        }

    }

Und meine Absicht:

public void showNotification(String ticker, String title, String message, 
    String imgUrl){
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = 
        (NotificationManager) getSystemService(ns);
    int icon = R.drawable.icon;        //icon from resources
    long when = System.currentTimeMillis();         //notification time
    CharSequence tickerText = ticker;              //ticker-text

    //make intent
    Intent notificationIntent = new Intent(this, activity.class);
    notificationIntent.putExtra("imgUrl", imgUrl);
    notificationIntent.setFlags(
        PendingIntent.FLAG_UPDATE_CURRENT | 
        PendingIntent.FLAG_ONE_SHOT);
    PendingIntent contentIntent = 
        PendingIntent.getActivity(this, 0, 
        notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | 
        PendingIntent.FLAG_ONE_SHOT);

    //make notification
    Notification notification = new Notification(icon, tickerText, when);
    notification.setLatestEventInfo(this, title, message, contentIntent);
    //flags
    notification.flags = Notification.FLAG_SHOW_LIGHTS | 
        Notification.FLAG_ONGOING_EVENT | 
        Notification.FLAG_ONLY_ALERT_ONCE | 
        Notification.FLAG_AUTO_CANCEL;
    //sounds
    notification.defaults |= Notification.DEFAULT_SOUND;
    //notify
    mNotificationManager.notify(1, notification);
}

Gibt es eine Möglichkeit, zu deutlich die Absicht oder überprüfen Sie, ob es verwendet wurde, vor?

Kommentar zu dem Problem
Können Sie Ihre codes? Kommentarautor: xandy
Ich habe den code auf meine Frage Kommentarautor: Mars
Anstelle von deaktivieren Absicht, Sie könnten bestimmen Sie den Start-Typ und der Handhabung der app flow entsprechend. Holen Sie sich die Extras nur, wenn es gestartet wurde, für die Meldung und nicht aus dem hintergrund. stackoverflow.com/questions/4116110/clearing-intent/... Kommentarautor: B.B.

InformationsquelleAutor der Frage Mars | 2010-11-07

Schreibe einen Kommentar