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

  • Home
  • SEARCH
  • 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 9217543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:39:24+00:00 2026-06-18T02:39:24+00:00

I am getting null while calling getSherlockActivity(); This is because the Activity is finished

  • 0

I am getting null while calling getSherlockActivity();

This is because the Activity is finished or killed

I could not come up with a solution to avoid in my case:

This SherlockActivity has a ViewPager with 4 Tabs.

adapter = new PagerAdapter((SherlockFragmentActivity) this, mViewPager);
adapter.addTab(actionBar.newTab(), Frag1.class, bundle);
adapter.addTab(actionBar.newTab(), Frag2.class, bundle);
adapter.addTab(actionBar.newTab(), Frag3.class, bundle);
adapter.addTab(actionBar.newTab(), Frag4.class, bundle);

When this Activity is launched, all the Tabs(Fragments) have an AsyncTask which uses getSherlockActivity() in doInBackground.

So, for all the AsyncTasks to complete, it takes around 3-5 secs, meanwhile if i press back and finish this Activity, the Last fragment Frag4 which didn’t yet started its AsyncTask(might be queued) tries for getSherlockActivity() and gets crashed.

I could just use a Try-Catch block and solve this, but is there a way i can tell the Fragments If the parent Activity is dead, stop all your background tasks etc.. something like that?

Thank You

  • 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-18T02:39:25+00:00Added an answer on June 18, 2026 at 2:39 am

    Just call each fragment’s AsyncTask.cancel() in the Activity onDestroy() callback. That way, the asynctasks aren’t going to perform anything based on the destroyed Activity context.

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

Sidebar

Related Questions

I'm getting this error django.db.utils.IntegrityError: django_content_type.name may not be NULL while running tests via
I'm getting InvalidObjectException: Could not find a SessionFactory named: null after restart of tomcat
i'm getting a weird null pointer exception in the last line of this code:
I'm getting a stack overflow error on some, but not all, IE7 machines. This
I am getting null while I try to obtain a loaded store from the
I am getting this error while loading a custom dijit. I have done this
I'm getting a Null Pointer Exception while in executing a macro to do some
I am getting NULL pointer exception currently, when I run this thread public void
I am getting null-exception throw error in the following code. What can be the
IN JAVA CODE IN JSP as below i m getting null value for fieldnoOfRecords.

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.