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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:58:06+00:00 2026-06-13T10:58:06+00:00

Im calling a function in my activity, which is basically an asynchronous task to

  • 0

Im calling a function in my activity, which is basically an asynchronous task to fetch data from a remote server via webservice.

 private void myAsyncTask() {
            new AsyncTask<Object, Object, Object>() {

                @Override
                protected void onPreExecute() {

                    progress_Dialog = ProgressDialog.show(a, "", "Loading");

                }

                @Override
                protected Integer doInBackground(Object... params) {


                    try
                    {
                    try {

                        MenuService menuService = new MenuServiceImpl();

                        MenuServiceResponse partnerMenu;
                            partnerMenu = menuService.getMenu();

                        productlist=Menu.getMenu().getMenuEntries();

                        System.gc();
                        return 0;
                    } catch (myServiceException e) {
                        bgFlag=true;

                        e.printStackTrace();
                    }
                    }
                    catch (Exception e) {

                        bgFlagForserviceExeption=true;
                        e.printStackTrace();


                    }
                    }                           return 0;
                }


                @Override
                protected void onPostExecute(Object result) {
                    if (progress_Dialog != null) {

                        progress_Dialog.dismiss();

                    }

                    try
                    {

                        if(bgFlagForserviceExeption)
                        {
                            MyAlertDialog.ShowAlertDialog(ShopActivity.this, "", "Please try again later", "OK");

                        }
                        if(bgFlag==false)
                        {
                     adapter = new ShopAdapter(
                            ShopActivity.this, productlist);

                                    allproduts.setAdapter(adapter);
                        }
                        else
                        {
                            MyAlertDialog.ShowAlertDialog(ShopActivity.this, "", " Please try again later", "OK");

                        }


                    }
                    catch(Exception e)
                    {
                        adapter=null;
                }

                }

            }.execute();



}

When i call this activity the progress bar will be shown until the doinbackground() ends.How can i exit from the background process on pressing phones back button,Right now the problem is i will have to wait until the background process completes even if i press the back button.How can i achieve this

  • 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-13T10:58:07+00:00Added an answer on June 13, 2026 at 10:58 am

    Override the back button.

    Here it is

    In that simply call asynctack.cancel(true);

    Read here

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

Sidebar

Related Questions

My main activity My_Gallery is calling a function from another class DataCall. In DataCall
I'm trying to return a value from (transport) to the calling function, but can't
Possible Duplicate: calling ASP function from javascript okay running this code : <script type=text/javascript>
I am calling a function funcB from funcA . funcB uses several printf statements
I'm calling a function from an input radio button and have this: onClick=\changeBilling('.$results['id'].', this.value)\
I am calling a function in my controller from a button click .... I
I'm logging to bank account and getting account balance. I calling this function from
I am calling a class's member function from another class. So,I am creating an
I get an error passing back an object from function to calling function. What
Does anyone know how to watch a variable in calling function. For example: C#:

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.