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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:29:16+00:00 2026-06-02T08:29:16+00:00

I would like to start a Thread when the Android started, so I made

  • 0

I would like to start a Thread when the Android started, so I made something like this

public class StartUpWelcomer extends BroadcastReceiver {

    @Override
    public void onReceive(Context arg0, Intent arg1) {
        // TODO Auto-generated method stub
        arg0.startService(new Intent(arg0, StartUpService.class));
    }

With my Manifest:

<receiver android:name=".StartUpWelcomer">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>
<service android:enabled="true" android:name=".StartUpService" />

And this is my StartUpService class

public class StartUpService extends Service {

    @Override
    public IBinder onBind(Intent arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    public void onCreate()
    {
        BackgroundApplication application = (BackgroundApplication)this.getApplication();
        ReminderThread reminderThread = new ReminderThread(null);
        if(!reminderThread.failed)
        {
            reminderThread.start();
            application.setRunningThread(reminderThread);
            Log.d("SERVICE", "CREATION CONFIRMED");
        }
        else
        {
            Log.d("SERVICE", "CREATION CANCELLED");
        }
    }

And here’s the code for the ReminderThread class

public ReminderThread(Context ctx)
{
    this.ctx = ctx;
    db = new SQLdb(ctx);
    //And there's some other code here that accessed the database functions.
}

OK, so here’s my intention… I would like the StartUpWelcomer to activate the StartUpService (and it’s working).

StartUpService will instantiate a new Thread, activating it and keeping it accessible in my application (which is called as BackgroundApplication class).

And here’s the problem… The ReminderThread actually need to access database (SQLite here), so the ReminderThread instantiated the database to access it. But, my database constructor need a Context to be instantiated. I have no idea where to get the Context here (from the Service class) where I usually get it from Activity class…. (temporarily I put “null” there)

Another problem is, somehow I found that this always cause a NullPointerException…

  • 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-02T08:29:17+00:00Added an answer on June 2, 2026 at 8:29 am

    If you initialize ReminderThread in Service then use ApplicationContect like new ReminderThread(getApplicationContext()); which is found in Service class.

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

Sidebar

Related Questions

I have a Java Thread like the following: public class MyThread extends Thread {
I would like to know how to start and code a thread manager for
In an given Android activity, I would like to start a new activity for
In my android service, I'm starting a new thread like this thread = new
in a Spring MVC Controller I would like to start a thread that continues
I would like start with .NET Micro Framework as my hobby project. What hardware
I would like to start making code patches to Rails. Are there any good
I would like to start a personal project that will give me a lot
I would like to start with x no. of fields (in my app I
I would like to start a community discussion. As per my question, when do

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.