Getting data from clicked notification in android

前端 未结 1 1135
花落未央
花落未央 2021-01-15 05:36

Hey guys I need help on how to get the data from my pending intent which is set using a broadcast receiver. What I want to happen is to get the data of an id when the notifi

相关标签:
1条回答
  • 2021-01-15 06:23

    In your AlertReceiver, you have declared

    private int id;
    

    and you use this int value in

    reminderActivity.putExtra("id", id);
    

    So you also have to get it as an int in your setContentFromDB() method:

    int reminderID = extras.getIntExtra("id", someInt);
    titleTextView.setText("" + reminderID);
    

    where 'someInt' should be an int value which is normally never used or a default value if that makes sense in your case.

    You got null from getStringExtra("id") because that's the return value if no String with key "id" was found.

    And if you use an int value with TextView.setText(), it will be interpreted as a string resource. I think in your case ('id' is meant for database) that's bad.

    0 讨论(0)
提交回复
热议问题