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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:13:32+00:00 2026-06-15T06:13:32+00:00

I like to make the application start service while user unlock his phone.When I

  • 0

I like to make the application start service while user unlock his phone.When I start unlock phone, there is happen nothing, and when I login the application(after login, it will runs ThirdActivity.java), the application is force stopped.The error log has shown as following:

11-28 14:28:52.846: E/AndroidRuntime(6439): FATAL EXCEPTION: main
11-28 14:28:52.846: E/AndroidRuntime(6439): java.lang.RuntimeException: Unable to start  activity    ComponentInfo{com.example.android.project/com.example.android.project.ThirdActivity}:   java.lang.NullPointerException: println needs a message
11-28 14:28:52.846: E/AndroidRuntime(6439):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2205)
11-28 14:28:52.846: E/AndroidRuntime(6439):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2240)
11-28 14:28:52.846: E/AndroidRuntime(6439):     at android.app.ActivityThread.access$600(ActivityThread.java:139)
11-28 14:28:52.846: E/AndroidRuntime(6439):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
11-28 14:28:52.846: E/AndroidRuntime(6439):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-28 14:28:52.846: E/AndroidRuntime(6439):     at android.os.Looper.loop(Looper.java:156)
11-28 14:28:52.846: E/AndroidRuntime(6439):     at android.app.ActivityThread.main(ActivityThread.java:4987)
11-28 14:28:52.846: E/AndroidRuntime(6439):     at java.lang.reflect.Method.invokeNative(Native Method)
11-28 14:28:52.846: E/AndroidRuntime(6439):     at java.lang.reflect.Method.invoke(Method.java:511)
11-28 14:28:52.846: E/AndroidRuntime(6439):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-28 14:28:52.846: E/AndroidRuntime(6439):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-28 14:28:52.846: E/AndroidRuntime(6439):     at dalvik.system.NativeStart.main(Native Method)
11-28 14:28:52.846: E/AndroidRuntime(6439): Caused by: java.lang.NullPointerException: println needs a message
11-28 14:28:52.846: E/AndroidRuntime(6439):     at android.util.Log.println_native(Native Method)
11-28 14:28:52.846: E/AndroidRuntime(6439):     at android.util.Log.d(Log.java:138)
11-28 14:28:52.846: E/AndroidRuntime(6439):     at com.example.android.project.ThirdActivity.onCreate(ThirdActivity.java:52)
11-28 14:28:52.846: E/AndroidRuntime(6439):     at android.app.Activity.performCreate(Activity.java:4538)
11-28 14:28:52.846: E/AndroidRuntime(6439):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
11-28 14:28:52.846: E/AndroidRuntime(6439):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
11-28 14:28:52.846: E/AndroidRuntime(6439):     ... 11 more

Before I add the codes following, it runs as usual:

    intentFilter = new IntentFilter();
    intentFilter.addAction(MyService.MY_ACTION);
    registerReceiver(intentReceiver, intentFilter);

    private BroadcastReceiver intentReceiver = new BroadcastReceiver() {...};
    protected void displayNotification(){...}

Anyone has any advice for this problem?

Here is StartMyServiceAtBootReceiver.java

public class StartMyServiceAtBootReceiver extends BroadcastReceiver{

    public void onReceive(Context context, Intent intent) {
          if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
                 HttpTest(context);                             
           }
     }

    public static boolean isNetworkAvailable( Context startMyServiceAtBootReceiver ) {
        Context context = startMyServiceAtBootReceiver.getApplicationContext();
        ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivity == null) {
        return false;
        } else {
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null) {
        for (int i = 0; i < info.length; i++) {
        if (info[i].getState() == NetworkInfo.State.CONNECTED) {
        return true;
        }
        }
        }
        }
        return false;
        } 

    public static void HttpTest( final Context startMyServiceAtBootReceiver)
    {
    if(isNetworkAvailable( startMyServiceAtBootReceiver) ){

         Intent start = new Intent(startMyServiceAtBootReceiver, MyService.class);
         start.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         startMyServiceAtBootReceiver.startService(start);
    }
    }

  }

MyService.java

public class MyService extends Service{

int counter = 0;
static final int UPDATE_INTERVAL = 15000;
private Timer timer = new Timer();
DefaultHttpClient httpclient;
HttpPost httppost;
String line,result;
HttpResponse response;
InputStream is;
BufferedReader reader;
StringBuilder sb;
final static String MY_ACTION = "MY_ACTION";

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


public int onStartCommand(Intent intent, int flags, int startId){
    doSomethingRepeatedly();
    return START_STICKY;        
}

private void doSomethingRepeatedly(){
    timer.scheduleAtFixedRate(new TimerTask(){
        public void run(){
        //  Log.d("MyService", String.valueOf(++counter));
            try{
             httpclient = new DefaultHttpClient();
                httppost = new HttpPost("http://www.kryptoquest.com/testing/checking.php");
                response = httpclient.execute(httppost);
                is = response.getEntity().getContent();
        }catch(Exception e){
            Log.e("log_tag", "Error:"+e.toString());
        }

        //convert response to string
        try{
                    reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                sb = new StringBuilder();
                line = null;
                while ((line = reader.readLine()) != null) {

                        sb.append(line + "\n");

                }
                Log.d("test",sb.toString());
                is.close();

                result = sb.toString();

             Intent intent = new Intent();
             intent.setAction(MY_ACTION);

             intent.putExtra("DATAPASSED", result);

             sendBroadcast(intent);


        }catch(Exception e){
                Log.e("log_tag", "Error converting result "+e.toString());
        }
        }
    },10000,UPDATE_INTERVAL);
}




public void onDestroy(){
    super.onDestroy();

    if(timer != null){
        timer.cancel();
    }

    Toast.makeText(this, "Service Destroyed", Toast.LENGTH_SHORT).show();
}

  }

ThirdActivity.java

public class ThirdActivity extends ListActivity{
Bundle b;
String user,line,result,datapassed;
DefaultHttpClient httpclient;
HttpPost httppost;
HttpResponse response;
InputStream is = null;
BufferedReader reader;
StringBuilder sb;
ArrayList<NameValuePair> nameValuePairs;
ListView lv;
IntentFilter intentFilter;
int notification = 1;
String str = "";
String[] data;
int dlength;


public void onCreate(Bundle savedInstancesState){
    super.onCreate(savedInstancesState);
    setContentView(R.layout.list_screen);
    lv = (ListView) findViewById(android.R.id.list);
    Log.d("dg",user);
    getList();
    intentFilter = new IntentFilter();
    intentFilter.addAction(MyService.MY_ACTION);
    registerReceiver(intentReceiver, intentFilter);
    user = getIntent().getExtras().getString("user");
}

    public void getList(){
    new Thread(){
        public void run(){
            try{
                 httpclient = new DefaultHttpClient();
                 httppost = new HttpPost("http://www.kryptoquest.com/tracker/friendlist.php");
                 response = httpclient.execute(httppost);
                 is = response.getEntity().getContent();
            }catch(Exception e){
                Log.e("log_tag", "Error:"+e.toString());
            }

            //convert response to string
            try{
                    reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                    sb = new StringBuilder();
                    line = null;
                    while ((line = reader.readLine()) != null) {

                            sb.append(line + "\n");

                    }
                    Log.d("test",sb.toString());
                    is.close();

                    result = sb.toString();

                    final String[] friend = result.split("[*]");

                    runOnUiThread(new Runnable()
                    {
                        public void run(){                              
                            setListAdapter(new ArrayAdapter<String>(ThirdActivity.this,android.R.layout.simple_list_item_1,friend)); 
                        }
                    });


            }catch(Exception e){
                    Log.e("log_tag", "Error converting result "+e.toString());
            }
        }
    }.start();
}

 private BroadcastReceiver intentReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
        datapassed = intent.getStringExtra("DATAPASSED");
        if(datapassed.length()>0){

            data = datapassed.split("[*]");
            dlength = data.length;

            for(int i=0;i<dlength;i++){
                if(i==dlength-1){
                    str += String.valueOf(data[i]);                 
                }else{
                    str += String.valueOf(data[i]) + ",";
                }   
            }
            Log.d("dataServices",str);
            displayNotification();
                str = "";           
        }
        }
        };

        protected void displayNotification(){
            Intent i = new Intent(this,NotificationView.class);
            i.putExtra("notification", notification);
            i.putExtra("name",str);
            Log.d("String",str);
            PendingIntent pi = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

            NotificationManager mnotis =(NotificationManager)getSystemService(NOTIFICATION_SERVICE);

            Notification notis = new Notification(R.drawable.notices2,"Reminder:You have " + dlength + " new friend request",System.currentTimeMillis());
            notis.setLatestEventInfo(this,"Friend Request", str + "has sent you a friend request",pi);
            notis.vibrate = new long[]{100,250,100,500};
            mnotis.notify(0, notis);
        }
           }
  • 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-15T06:13:34+00:00Added an answer on June 15, 2026 at 6:13 am

    In the onCreate() you have this line Log.d("dg",user); at this line user variable would always be null since you area assigning the value at the end of the onCreate() method. Move this line to end of the onCreate() method and also check for null value, only call the log.d if the value is not null..

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

Sidebar

Related Questions

I would like to make my application ask the user some informations via something
I would like to make my own user-mode NAT application. I have the folowing
I have an application where I would like to make my reducers (I have
In our application, we would like to make a link to an online help
I'm developing a free application and would like to make some money by embedding
I have made a small application in Java and I would like to make
I'm building a Zend Framework 1.11.11 application and would like to make the routes
I'm currently in a .NET4 Windows Forms Application. I'm trying to make something like
Im trying to make a photoshop like application for my college project in c#
I want to make a number selector like in alarm application, which has two

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.