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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:59:35+00:00 2026-06-14T16:59:35+00:00

I have a android Service, in the onStart method i get many Strings from

  • 0

I have a android Service, in the onStart method i get many Strings from the Intent activity, and then execute a AsynTask to download files from internet.

When the activity is running this works ok, but when i stop the activity, this relaunch the onStart method, but obiusly the intent is null causing me nullPointerException.

What can i do the service dont entry on onStart, and continues the first asyntask to download all the files?

This is my code

    @Override
    public void onStart(Intent intent, int startId) {
        desde = intent.getIntExtra("desde", 0);
        hasta = intent.getIntExtra("hasta", 1);
        email = intent.getStringExtra("email");
        password = intent.getStringExtra("password");

        new DescargaFotos().execute();

    }

@Override
    public IBinder onBind(Intent intent) {

        return null;
    }

and in Inicio.java (The UI activity)

Intent iService = new Intent(contexto,


    ServiceDownloader.class);
                            iService.putExtra("desde", 0);
                            iService.putExtra("hasta", 5);
                            iService.putExtra("email", email);
                            iService.putExtra("password", password);
                            startService(iService);     

EDIT:

New question:

I am using IntentService and i bind the service like this:

Intent iService = new Intent(contexto,
                                ServiceDownloader.class);

                        ServiceConnection serviceConector = new ServiceConnection() {

                            @Override
                            public void onServiceDisconnected(ComponentName name) {
                                Log.i("INFO", "Service bound ");
                            }

                            @Override
                            public void onServiceConnected(ComponentName name,
                                    IBinder service) {
                                Log.i("INFO", "Service Unbound ");
                            }
                        };

                        iService.putExtra("desde", 0);
                        iService.putExtra("hasta", 50);
                        iService.putExtra("email", email);
                        iService.putExtra("password", password);
                        startService(iService);
                        bindService(iService, serviceConector,
                                Context.BIND_AUTO_CREATE);

And now my problem is, in my galaxy nexus, if i enter in app runtime list, and destroy my app, the service stopped, and stop donwload, stop send notification etc? How must i bind the service to solve 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-14T16:59:36+00:00Added an answer on June 14, 2026 at 4:59 pm

    Use an IntentService. IntentService is specifically designed to do what you want. You don’t have to implement onStart, onStartCommand, etc. The work runs on a background thread. Once the work finishes, the Thread is destroyed.

    IntentService will continue to run regardless of the state of the Activity.

    One problem you may have is that you’re sending out your Intent in the wrong place in your Activity, or you’re not checking to see if the operation is complete. Before you send the Intent, check a flag in SharedPreferences (if the flag doesn’t exist, it means you’re starting for the first time). When you send the Intent, store a flag in SharedPreferences to indicate that you sent it. When your IntentService receives the Intent, have it update the flag to say it received it. Before the IntentService finishes, have it update the flag again. And so forth.

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

Sidebar

Related Questions

I have an Android service which I start from the main activity. The service
I have an android recurring service running in background, no Activity running in front
We have an Android app and a Web Service. We want to download part
I have accessed a web service from Android 2.2.It is perfectly OK.I changed my
I have an Android Service running in a separate process from its client, and
I have been trying to get this android service working but I can not
I have an Android service, created in OnCreate of first Activity of the application
I have an android service, I bound it to an activity, and unbound on
I have an Android service which sends broadcast intents. I'm trying to get those
I have a custom Android Service (with no associated Activity) that needs to implement

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.