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 8199341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:08:58+00:00 2026-06-07T06:08:58+00:00

i am building an application for clients to get questions from server and answer

  • 0

i am building an application for clients to get questions from server and answer it, if the server doesn’t have questions i want to go to new screen and print message that try again in few minutes, getting questions is in AsyncTask , if the server doesn’t have questions , it will sends in the header of the responds, a header isFindAQuestion with the value false, here is the code on client to ensure if false , i print on LogCat and i see the message = false, but my problems that even if i start new activity with the intent, this activity keep working and show me exception and it is null pointer exception because on the onPostExceute will take a parmeter null and try to process it, i put finish() in the end of false statement but doesn’t finish the activity

if (response.getFirstHeader("isFindAQuestion").getValue()
                        .toString().equals("false")) {
                    Log.d("message", "false");
                    Bundle basket = new Bundle();
                    basket.putString("Message", "sorry no enought questions");
                    Intent goToAnswerQuestion = new Intent(AnswerQuestion.this,
                            FinishTime.class);
                    goToAnswerQuestion.putExtras(basket);
                    startActivity(goToAnswerQuestion);
                    finish();

                } 

Edit

is it because AsyncTask is working on thread so if the activity is finished, that thread will keep working? and if so how can i stop that thread?

  • 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-07T06:08:59+00:00Added an answer on June 7, 2026 at 6:08 am

    doInBackground is not executed in the UI thread, but in a separeted thread:

    invoked on the background thread immediately after onPreExecute()
    finishes executing. This step is used to perform background
    computation that can take a long time.

    If you want to stop your background operation and perform some activities on the UI thread the better thing is to call cancel() and then perform all the stuff you want in the onCancelled callback wich is executed on the UI thread.

    From the AsyncTask documentation:

    A task can be cancelled at any time by invoking cancel(boolean).
    Invoking this method will cause subsequent calls to isCancelled() to return true. After invoking this method, onCancelled(Object), instead of onPostExecute(Object) will be invoked after doInBackground(Object[]) returns.
    To ensure that a task is cancelled as quickly as possible, you should always check the return value of isCancelled() periodically from doInBackground(Object[]), if possible (inside a loop for instance.)

    protected void onCancelled (Result result)
    

    Runs on the UI thread after cancel(boolean) is invoked and doInBackground(Object[]) has finished.
    The default implementation simply invokes onCancelled() and ignores the result. If you write your own implementation, do not call super.onCancelled(result).

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

Sidebar

Related Questions

We are building a new application in .net 3.5 with SQL server database. The
I'm building an application in Python2.6 that needs to get data from CouchDb. I'm
I'm building an XE2 DataSnap server which will serve connections from REST clients. My
I'm currently building a Facebook Application for a client using the new timeline layout
i am building a server application using eclipse , and the client is android
Building an application with a database that has the ability to get big not
For one of my clients I'm currently building an application that communicates with a
I'm building an application, it's easy and what I want to do is the
I'm building client/server apllication on QT. I just want user to execute only one
Started building an application here. client and server style architecture sending active resources across

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.