Android application acting crazy after coming from background

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 crazy....

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?

Asked by: Elise562 | Posted: 20-01-2022

Answer 1

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:

Answered by: Ada365 | Posted: 21-02-2022

Answer 2

Are you calling the super in your OnCreate?


Answered by: Emma733 | Posted: 21-02-2022

Similar questions

multitasking - Android Custom URL Scheme - Source application

Is there a way to get the source application in Android when launched via custom URL Scheme? Our app is controlled via the browser on the device. you click a certain link, and depending on the arguments, a task is performed. I want to then immediately get back to the browser. I tried calling moveTaskToBack(true) once the task is finished, but for some reason, it takes me back to the home screen...

multitasking - Keep android application open

On the Android Market there is an app called Sleep Timer, and it is a type of alarm clock that brings runs the alarm even though you locked your phone while on facebook. I made a type of app that detects movement however it only works if the phone is left on that app... How can I make it work when the app wasn't left upfront, but is still running in the background?

How does a multitasking android application with floating dialog work?

Have come across few Android applications that can display a Dialog on foreground, that is not from the currently active foreground Activity, but perhaps from a background service (if I get the notion right). There is a floating browser, floating note-taker etc. The dialog is an interactive one, i.e. it has buttons that can pressed, text area which can be edited etc. They usually have a translucent background, through whic...

multitasking - Android ==> disable multi tasking?

1- How can i disable multi tasking? My application is a socket based game, every time i start the app, it MUST load the main page first to start the socket connection? I do not want the user to be able to run my application in background. Is this possible to do? 2- I do not want the user to be able to use the back button, to navigate between pages, users must only use the buttons available in my application to nav...

multitasking - Android - Detect `App Became Active' from Mulitiasking?

I have developed an Android App that contains a list of information. I want the list to retrieve new data from the sever whenever the app 'wakes up' from multasking. Right now it just displays the old data and does not refresh. Can someone tell me what function/method I am looking for?

multitasking - Working with onPause, onRestart, in Tab Widget - Android

I have a ListView that is inside a TabWidget. When I select an item on the ListView and go to the child ListView, the TabWidget disappears. This is fine, except that it invokes the onPause method, and thus causes onRestart to be called when I return to the parent ListView. I have onRestart setup to r...

java - Android multitasking problem

I have an android application which main view consists of a tab-bar with three tabs in it. When developing and running the application on the device through adb I get the following behavior: When clicking the phone button "Home screen" and relaunching the application it seems as the application continues where I was before pressing the button (remembers selected tab etc...) (apparently its still runni...

multitasking - Android multitaksing

I am seeking short characteristic of Android Multitasking. I have found, that when you minimize Android application, it is ended and it's process remains on the background. When user wants to reuse his app, this process alive it's application. User will be at the same state, when he left (if there was enough memory while working with it), or it will be loaded from scratch, because there was no free RAM for other work and A...

multitasking - How to architect my android app around a 20 minute http session

I have an android app that I'm building and it's based on a web app that lets users login and reserve a book (think library). Because you are able to reserve books it needs to have a valid session (cookie to be exact) Here is my issue - how can I work with multitasking when I have this 20 minute constraint? Do I keep a timer running the entire time the app is up (in the Application global object) -then on r...

Android Activity back stack and multitasking support

I have an app that supports multitasking (working in the background), however I have run into problems with the android backstack. This is what I have: Activity A starts Activity B for result, so... Activity A --> Activity B If when at Activity B the user long presses the home button and switches to another application (say the browser for example) and then long presses the ...

android - Phonegap + Multitasking audio

I'd like to code my phonegap app so at a minimum the audio that is streaming/playing can stay active across pages. Even better would be a way to have it interact with the OS and stop when a call comes in or they play their own music or something else. Has anyone accomplished either of these things yet? Thanks!

java - Proper multitasking for android

Hi im developing an android application and im wondering how i make the app use less CPU while backgrounded. For example, my application pauses once it loses focus but the cpu usage is still 50% Edit while (!pause) { Canvas c = null; try { c = sHolder.lockCanvas(null); synchronized (sHolder) { doDraw(c); ...

java - How can i create multitasking between activities?

I want to display two activities at a time and can work on both simultaneously. Is it possible ? if possible please give me some example. I am working in android 2.2 froyo. Thanks in advance

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Android