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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:44:01+00:00 2026-05-26T17:44:01+00:00

In my app, the activity starts a thread which download images from server. There

  • 0

In my app, the activity starts a thread which download images from server. There are more than 30 images. While downloading, the user can switch to another activity. So I want that the thread should stop doing whatever it is doing. I have used mThread.interrupt() method in onDestroy(), but it did not worked. How to do that?

  • 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-05-26T17:44:02+00:00Added an answer on May 26, 2026 at 5:44 pm

    I can suggest simpler&safer approach to handle this

    Use common value across your app;
    SharedPreferences or inside Application context
    Key=IsStopDownload
    Value= True / False

    part.1)
    in Application context (MyApplication)

    private boolean isAppActive = false;
    public void setAppState(Context context, boolean state) {
        isAppActive = state;
        // note: you can also store this in SharedPreferences
    }
    public boolean getAppState(Context context) {
        return isAppActive;
        // note: you can also load this from SharedPreferences
    }
    

    part.2)
    Activity onResume and onPause are the guaranteed places to identify state of your activity.

    onResume -> activity is active
    onPause -> activity is not active

    part.3)
    let your thread check the activity state and if not active, it can stop itself, thats safer then making external interrupt. threads can act weird when interrupted from outside, it is safer to break the loop from inside.

    e.g.

    ((MyApplication)context.getApplicationContext()).getAppState(context);
    

    if thats false, thread stops itself

    hope this helps…

    —
    Social Coding @AspiroTV

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

Sidebar

Related Questions

i am creating app which would download and save files, than user could use
I have an app in android that in a different thread from the UI(which
I have an Android app which includes an activity called Help This uses a
I have a home page activity that I got from an example, which works
I have an application which upon start request around 10-12KB of data from server
I have a backgorund thread that extends AsyncTask and which I use in activity
Im writing an app which loads data from a rest interface. for this task
i am designing a app for some quiz. i need an activity that starts
In my app have a sign in activity. If login is successful, I start
I would like to implement the following simple pattern in an android app: Activity

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.