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

2条回答
爷的心禁止访问
2楼-- · 2019-06-16 18:46

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

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

It should work.

查看更多
SAY GOODBYE
3楼-- · 2019-06-16 18:47

This is what worked for me:

onCreate(new Bundle()); 
查看更多
登录 后发表回答