开发者

Android application acting crazy after coming from background

开发者 https://www.devze.com 2022-12-13 19:20 出处:网络
I am displaying search results from a webservice. What I do is OnCreate I hit the webservice display records, as android supports multitasking. If user opens another screen and after some time comes

I am displaying search results from a webservice.

What I do is OnCreate I hit the webservice display records, as android supports multitasking. If user opens another screen and after some time comes back to the search results page, the application starts acting cr开发者_StackOverflow中文版azy....

OnCreate method I load data some thing like :

private void loadData() throws Throwable{
        try {
            jsonArray = JSONService.getJsonArray(getResources().getString(R.string.catJson));
        } catch (Throwable e) {
            Log.e(TAG, e.getMessage());
            throw e;
        }
    }

and then I iterate through json array and change labels value to display result on the screen.

Any ideas how to fix this?


Yes, please explain our problem better. Are you familiar with the Activity life-cycle? There are several different callbacks that you must manage in order for your concept of multitasking to actually work. Based on the limited info you've provided, I don't think you're saving any of your application state when your Activity loses focus. So your process may be getting shutdown and when you come back, your JSON array is gone. Read this: http://developer.android.com/guide/topics/fundamentals.html#lcycles


Are you calling the super in your OnCreate?

super.onCreate(savedInstanceState);
0

精彩评论

暂无评论...
验证码 换一张
取 消