Strong Android Link

I have a SearchCritiera object and I make it singleton and declare this variable as static, now the problem is that if I left my application open for a couple of hours that the static object is deleted by Android OS, how can I make sure that the static object is not must be removed by the OS.

as i know there are several keywords like

Weekreference and softreference, is there any strongreference keyword that can say that Android OS is not deleting the link?

+5
source share
3 answers

, , ( , ).

, Application. , .

+3

, Android . , , .

, , , , , . , , , .

, , , , .

, Androd . , .

+1

If I'm not mistaken when the application remains open for a long time, the data will be released by the Android OS, and while the stopiong operation will call "onSaveInstanceState", and when can I save the searchritiera in this method and whether it will return when " onRestoreInstanceState "caused by?

private static SearchCriteria searchCriteria;


@Override 
    public void onSaveInstanceState(Bundle outState) 
    {
        outState.putSerializable(WLConstants.SEARCH_CRITERIA, searchCriteria);
        super.onSaveInstanceState(outState); 
    }
    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        if(savedInstanceState != null){
            searchCriteria = (SearchCriteria)
            savedInstanceState.getSerializable(WLConstants.SEARCH_CRITERIA);
        }
        super.onRestoreInstanceState(savedInstanceState);
    }
+1
source

All Articles