Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8761647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:20:14+00:00 2026-06-13T15:20:14+00:00

This MAY be a duplicate of another question, I am not sure. I’ve read

  • 0

This MAY be a duplicate of another question, I am not sure. I’ve read similar questions, but either wasn’t able to make sense of it, or wasn’t able to successfully apply the given solutions.

I’ve created an application that has multiple tabs. Most tabs use an ASyncTask to update data when the users slides into the tab. However, when something about the activity changes while the AST is still running (that happens a lot; eg when the user rotates the screen or exits using the back button), the application will force close (ANR).

Here’s what I see happening in my LogCat:

10-30 11:30:01.422: E/AndroidRuntime(4687): FATAL EXCEPTION: main
10-30 11:30:01.422: E/AndroidRuntime(4687): java.lang.NullPointerException
10-30 11:30:01.422: E/AndroidRuntime(4687):     at com.appconstructor.khcreates.Core$refreshList.onPostExecute(Core.java:913)
10-30 11:30:01.422: E/AndroidRuntime(4687):     at com.appconstructor.khcreates.Core$refreshList.onPostExecute(Core.java:1)
10-30 11:30:01.422: E/AndroidRuntime(4687):     at android.os.AsyncTask.finish(AsyncTask.java:631)
10-30 11:30:01.422: E/AndroidRuntime(4687):     at android.os.AsyncTask.access$600(AsyncTask.java:177)
10-30 11:30:01.422: E/AndroidRuntime(4687):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
10-30 11:30:01.422: E/AndroidRuntime(4687):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-30 11:30:01.422: E/AndroidRuntime(4687):     at android.os.Looper.loop(Looper.java:137)
10-30 11:30:01.422: E/AndroidRuntime(4687):     at android.app.ActivityThread.main(ActivityThread.java:4745)
10-30 11:30:01.422: E/AndroidRuntime(4687):     at java.lang.reflect.Method.invokeNative(Native Method)
10-30 11:30:01.422: E/AndroidRuntime(4687):     at java.lang.reflect.Method.invoke(Method.java:511)
10-30 11:30:01.422: E/AndroidRuntime(4687):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-30 11:30:01.422: E/AndroidRuntime(4687):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-30 11:30:01.422: E/AndroidRuntime(4687):     at dalvik.system.NativeStart.main(Native Method)

From what I can see, the ASyncTask (refreshlist) can’t handle the fact that there’s no application left to apply the change to.

What I want to do is make an application that doesn’t force close if there’s no activity.

  1. EITHER I want the ASyncTask to stop if the activity stops
  2. OR I want the application to just keep the task running, but not force close (eg: nothing happens onPostExecute() if there’s no activity connected.

If someone needs my onPostExecute() code to solve the problem, let me know.

This has been bugging me for a while, and I haven’t been able to solve this for myself. My app’s experience is pretty horrible with this bug in place. Help would VERY much be appreciated!

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:20:15+00:00Added an answer on June 13, 2026 at 3:20 pm

    It’s better to execute cancel(true) with same instance that you used for execute() command:

    AsyncTask<Void,Void,Void> task = new MyAsyncTask();
    task.execute();
    
    .....
    
    task.cancel(true);
    

    EDIT:You need to store instance of your AsyncTask individualy in each fragment, so save instance of new freshList(this,getActivity(),mNum) as you fragment’s variable and, since this is a fragment, execute cancel(true) in onPause() method of your fragments. Hope this will help you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may be a duplicate question, but really don't know how else to word
I know this question may be a duplicate of some other ones, but I
I know you may regard this post as another duplicate, while it's not. It's
This may have already been answered in another post, but I just am not
Firstly , This may look like a duplicate question but trust me I have
My apologies if this is a duplicate; I may not know the proper terms
This may be a stupid question but I have a code with the following
This may be a simple question but I can;t find the answer anywhere. Here
At first glance, this question may seem like a duplicate of How to detect
I posted this question here before but there were no responses. I may have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.