Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
382 views
in Technique[技术] by (71.8m points)

java - getLastNonConfigurationInstance always returning null

HashMap myMap = (HashMap) getLastNonConfigurationInstance();

myMap is always null. getLastNonConfigurationInstance() returns an object. My map has two keys "symbol" and "name".

public Object onRetainNonConfigurationInstance()
    {
        HashMap myMap = new HashMap();
        myMap.put("symbol", this.symbol);
        final Object data = myMap;
        return data;
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I faced the same issue. Looks like calling getLastNonConfigurationInstance() in anything other than onCreate() returns null. I moved the statement to onCreate() method and voila..it returned what I expected it to return.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...