Android, How to call onCreate() explicitly from ot

2019-06-16 18:21发布

问题:

I want to call onCreate(Bundle cicici); from other method then i am getting "NullPointerException", so please guide me how can i call the onCreate() from another method().

    public void moreFriendsButtonClick(int id)
{
    contentId= id;
    onCreate(tempBundle);
}

Here i am passing int value, and

tempBundle=savedInstanceState;

and after that i am getting NullPointerException

回答1:

you should create the bundle again. savedInstanceState is local to onCreate method. try

Bundle tempBundle = new Bundle();
onCreate(tempBundle);

It should work.



回答2:

This is what worked for me:

onCreate(new Bundle());