Handling onNewIntent in Fragment

后端 未结 3 1384
时光取名叫无心
时光取名叫无心 2021-01-17 08:28

I am writing an application that uses NFC to read some data stored on it. My application uses Fragments and Fragment don\'t come with onNewIntent() method. Since, the data I

3条回答
  •  忘掉有多难
    2021-01-17 09:13

    No, there is no better way. Fragments can live longer than Activities and are not necessarily tied to them at all so providing new intents would not make sense.

    Btw, you have a few bugs in your code :)

    if (actionBar.getSelectedNavigationIndex() != 1) {
    

    Magic numbers are bad! use a constant.

        if (myBalanceBundle == null)
            myBalanceBundle = new Bundle();
    
        myBalanceBundle.putString(Keys.BALANCE.toString(), balance);
        actionBar.setSelectedNavigationItem(1);
    

    we already know that the navigationitem is set to 1

    } else {
        newBlanceListener.onNewBalanceRead(balance);
    

    Add a null check. The user might have never selected a navigation item.

提交回复
热议问题