Android ActivityGroup - NullPointerException

后端 未结 3 1850
耶瑟儿~
耶瑟儿~ 2021-01-16 20:27

I\'m trying to use activity groups - since I use tabs, and want to have the tabs when loading and activity after the list item was clicked,. but I\'m getting nullpointerexce

3条回答
  •  萌比男神i
    2021-01-16 20:43

    I had the same problem. To solve it I decomposed the multi-call line into three lines as the first answer suggested:

                LocalActivityManager processManager =activityGroup.group.getLocalActivityManager();
                Window w = processManager.startActivity("ActivityOne", myIntent);
                View view = w.getDecorView();
    

    Then discovered that the first line is the problem one. Because I am calling ActivityOne from an activity outside of the activity group (it is an activity under a different tab), the static "activityGroup.group...." has not yet been initialised. So the rather kludgy fix is to switch to that tab and back to this tab before launching the intent. So add the following just before the code above:

                AppName.switchToTab(2);  
                AppName.switchToTab(1); 
    

    That did the trick and you can't see the tab switch. A more tidy solution would be maybe to switch to all the tabs on startup to ensure they are all initialised...

提交回复
热议问题