I am getting a strange problem which I am not able to understand as the app does not give any crash log or any other message which I can follow to search the problem.
I launching a service from my activity and in this service I am trying to find out the number of process which are in error state but when my code reaches to the line
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
then the app stops working. When I debugged my app then I found that after hitting the above line the debugger navigates to the file ActivityThread.java in cleanUpPendingRemoveWindows() with a message "Source code does not match the byte code". I am not able to understand why this is happening?
My code is:
import android.app.ActivityManager;
import android.app.Service;
import android.app.usage.UsageStats;
import android.app.usage.UsageStatsManager;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
public class Senddata_1 extends Service {
String TAG = "uEarn:Senddata_1";
public void find_out_process_in_error_state(){
List<ActivityManager.ProcessErrorStateInfo> processErrorStateInfos;
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
processErrorStateInfos = am.getProcessesInErrorState();
if(processErrorStateInfos != null) {
for (ActivityManager.ProcessErrorStateInfo pes : processErrorStateInfos) {
Log.e(TAG, "Process in Error state" + pes.processName);
Log.e(TAG, "Process error messga" + pes.shortMsg);
message = message + "<p>Process in Error state:" + pes.processName + ", error message:" + pes.shortMsg + "</p>\n";
}
}
return;
}
public Senddata_1() {
// TODO: Get the Filename through the intent
Log.e(TAG, "Inside service Senddata_1");
find_out_process_in_error_state();
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
// return;
}
}
the app does not give any crash log or any other message which I can follow to search the problem.
Oh, I strongly suspect that it does.
when my code reaches to the line... then the app stops working.
That is because you are trying to call methods inherited from Service
before you call super.onCreate()
in your onCreate()
method. The most typical exception will be a NullPointerException
.
Replace your constructor with:
@Override
public void onCreate() {
super.onCreate();
find_out_process_in_error_state();
}
Then, when you start the service, your find_out_process_in_error_state()
method will be called, when it should be safe for it to call getSystemService()
.