I have one activity which download data from the web. In middle of the downloading process application closes if I start downloading process more than one time. I am using AsyncTask to download data and Runnable to get the steps completed and. Here is my code. Do I have to remove callback for handler at finish of the task? If i put remove callback in pause or destroy method it gives force close error.
mBackgroundHandler = new Handler();
mRunnable = new Runnable()
{
public void run()
{
mCounterProgress = KamaApplication.getStep();
Log.v(TAG, "Progress: " + mCounterProgress);
mRefreshProgress.setProgress(mCounterProgress);
mRefreshProgress.invalidate();
if(KamaApplication.getTotalStep() == 100 && KamaApplication.getStep() == 99)
{
mStop = true;
}
if(!mStop)
{
mBackgroundHandler.postDelayed(this, 1000);
}
}
};
mBackgroundHandler.postDelayed(mRunnable, 1000);
Here is my AsyncTask
private class DownloadFilesTask extends AsyncTask<Void, Integer, Void>
{
protected Void doInBackground(Void... params)
{
try
{
StepsGeneratorInputJsonData stepsGeneratorInputJsonData = new StepsGeneratorInputJsonData();
stepsGeneratorInputJsonData.provider = "Android";
stepsGeneratorInputJsonData.identification = "Vogue";
stepsGeneratorInputJsonData.password = "abcd";
mResult = createAndExecuteStepsGenerator(stepsGeneratorInputJsonData);
JSONObject mNewJSONObject = new JSONObject(mResult);
String mEndDate = mNewJSONObject.getString("endDate");
if(mEndDate.equals("null"))
{
mRefreshSuccess = false;
}
else
{
mRefreshSuccess = true;
}
}
catch (Exception eException)
{
Log.v(TAG, "HotTestGettingError: " + eException.toString());
mRefreshSuccess = false;
}
return null;
}
protected void onProgressUpdate(Integer... progress)
{ }
protected void onPostExecute(Void result)
{
if(mRefreshSuccess)
{
insertData();
}
else
{
Message mMessage = new Message();
mMessage.what = 0;
mHandler.sendMessage(mMessage);
}
mBackgroundHandler.removeCallbacks(mRunnable);
updateDisplay();
}
}
And I saw the logcat and got this :
06-25 12:08:28.007: INFO/WindowManager(128): WIN DEATH: Window{408fc1d8 com.mygosoftware.kama/com.mygosoftware.kama.Usage paused=false}
06-25 12:08:28.011: INFO/ActivityManager(128): Process com.mygosoftware.kama (pid 17691) has died.
06-25 12:08:28.078: INFO/ActivityManager(128): Start proc com.sec.android.app.twlauncher for activity com.sec.android.app.twlauncher/.Launcher: pid=17817 uid=10015 gids={3003, 1015, 3002}
06-25 12:08:28.078: INFO/ActivityManager(128): Low Memory: No more background processes.
06-25 12:08:28.148: INFO/Zygote(17817): Zygote: pid 17817 has CALL PRIVILEGED permission, then set capability for CAP_SYS_ADMIN (21)
06-25 12:08:28.312: INFO/ActivityThread(17817): Pub com.sec.android.app.twlauncher.settings: com.sec.android.app.twlauncher.LauncherProvider
06-25 12:08:28.445: INFO/Launcher(17817): onCreate(): product model family:S1 product model : GT-I9000
06-24 16:47:38.269: ERROR/InputDispatcher(128): channel '40823250 com.mygosoftware.kama/com.mygosoftware.kama.Usage (server)' ~ Consumer closed input channel or an error occurred. events=0x8
06-24 16:47:38.269: ERROR/InputDispatcher(128): channel '40823250 com.mygosoftware.kama/com.mygosoftware.kama.Usage (server)' ~ Channel is unrecoverably broken and will be disposed!
06-24 16:47:38.304: INFO/ActivityManager(128): Process com.mygosoftware.kama (pid 7637) has died.
I have put in AndroidManifest file
<activity android:name=".Usage" android:screenOrientation="portrait"
android:clearTaskOnLaunch="true">
and also set
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
and also put
onPause()
method in my activity.
Moreover, I have referred this link Activity restarts on Force Close. Mine is very similar problem. I have done everything what they written in answer but still getting the error.
What should I do to remove this error?
Thanks.