Android后台服务刷出时崩溃

Android后台服务刷出时崩溃,android,service,background-process,Android,Service,Background Process,当我从任务管理器中删除我的应用时,剩下0个进程和1个服务。应用程序一次又一次崩溃我该怎么解决它?这是我的服务课。我想再问一件事OnStart()方法和OnStartCommand()方法之间的区别是什么 package com.example.vaculationsystem; 导入java.text.simpleDataFormat; 导入java.util.ArrayList; 导入java.util.Calendar; 导入org.ksoap2.SoapEnvelope; 导入org.ks

当我从任务管理器中删除我的应用时,剩下0个进程和1个服务。应用程序一次又一次崩溃我该怎么解决它?这是我的服务课。我想再问一件事OnStart()方法和OnStartCommand()方法之间的区别是什么

package com.example.vaculationsystem;
导入java.text.simpleDataFormat;
导入java.util.ArrayList;
导入java.util.Calendar;
导入org.ksoap2.SoapEnvelope;
导入org.ksoap2.serialization.PropertyInfo;
导入org.ksoap2.serialization.SoapObject;
导入org.ksoap2.serialization.SoapPrimitive;
导入org.ksoap2.serialization.SoapSerializationEnvelope;
导入org.ksoap2.transport.HttpTransportSE;
导入android.annotation.SuppressLint;
导入android.app.AlarmManager;
导入android.app.Notification;
导入android.app.NotificationManager;
导入android.app.pendingent;
导入android.app.Service;
导入android.content.Intent;
导入android.os.IBinder;
导入android.os.SystemClock;
导入android.util.Log;
导入android.widget.TabHost.OnTabChangeListener;
@SuppressLint(“覆盖”)
公共类后台服务扩展服务{
字符串用户标识;
SoapObject请求;
PropertyInfo p_用户ID;
信封;
httpTransport-httpTransport;
原始反应;
ArrayList listRec;
字符串s;
积分差;
int countNotification=0;
私有静态最终字符串方法\u NAME=“警报”;
私有静态最终字符串命名空间=”http://org.fyp.ws";
私有静态最终字符串SOAP_ACTION=”http://org.fyp.ws/Alerts";
私有静态最终字符串URL=StaticIP.ipAddress
+“GeneralUserServices?wsdl”;
@凌驾
公共IBinder onBind(意图arg0){
返回null;
}
//@覆盖
//public void onCreate(){
//
//Toast.makeText(这是“恭喜!MyService已创建”,
//Toast.LENGTH_LONG).show();
////Log.d(标记“onCreate”);
// }
@凌驾
公共无效启动(Intent Intent,int startId){
userId=intent.getExtras().getString(“用户Id”);
listRec=newarraylist();
请求=新的SoapObject(名称空间、方法名称);
p_userId=newpropertyinfo();
信封=新的SoapSerializationEnvelope(SoapEnvelope.VER11);
httpTransport=新的HttpTransportSE(URL);
p_userId.setName(“userId”);//在web中定义变量名
p_userId.setValue(userId);//为fname变量定义值
p_userId.setType(String.class);//定义变量的类型
request.addProperty(p_userId);//将属性传递给变量
envelope.setOutputSoapObject(请求);
试一试{
调用(SOAP_操作,信封);
response=(SoapPrimitive)envelope.getResponse();
//Toast.makeText(getApplicationContext(),response.toString(),
//Toast.LENGTH_LONG).show();
字符串[]行=response.toString().split(“`”);
for(int i=0;ipackage com.example.vaccinationsystem;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.annotation.SuppressLint;
import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.SystemClock;
import android.util.Log;
import android.widget.TabHost.OnTabChangeListener;

@SuppressLint("Override")
public class BackgroundServices extends Service {

String userId;
SoapObject request;
PropertyInfo p_userId;
SoapSerializationEnvelope envelope;
HttpTransportSE httpTransport;
SoapPrimitive response;
ArrayList<String> listRec;
String s;
int totalDifference;
int countNotification = 0;

private static final String METHOD_NAME = "Alerts";
private static final String NAMESPACE = "http://org.fyp.ws";
private static final String SOAP_ACTION = "http://org.fyp.ws/Alerts";
private static final String URL = StaticIP.ipAddress
        + "GeneralUserServices?wsdl";

@Override
public IBinder onBind(Intent arg0) {
    return null;
}

// @Override
// public void onCreate() {
//
// Toast.makeText(this, "Congrats! MyService Created",
// Toast.LENGTH_LONG).show();
// // Log.d(TAG, "onCreate");
// }

@Override
public void onStart(Intent intent, int startId) {


    userId = intent.getExtras().getString("user_Id");
    listRec = new ArrayList<String>();
    request = new SoapObject(NAMESPACE, METHOD_NAME);
    p_userId = new PropertyInfo();
    envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    httpTransport = new HttpTransportSE(URL);

    p_userId.setName("userId");// Define the variable name in the web
    p_userId.setValue(userId);// Define value for fname variable
    p_userId.setType(String.class);// Define the type of the variable
    request.addProperty(p_userId);// Pass properties to the variable

    envelope.setOutputSoapObject(request);


    try {

        httpTransport.call(SOAP_ACTION, envelope);
        response = (SoapPrimitive) envelope.getResponse();
        // Toast.makeText(getApplicationContext(), response.toString(),
        // Toast.LENGTH_LONG).show();

        String[] row = response.toString().split("`");

        for (int i = 0; i < row.length; i++) {

            String[] record = row[i].split("~");
            // totalDifference = 0;
            Calendar c = Calendar.getInstance();
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");

            String curDate = df.format(c.getTime()).toString();
            String visitDate = record[1];

            java.util.Date cD = df.parse(curDate);
            java.util.Date vD = df.parse(visitDate);

            Calendar cCurDate = Calendar.getInstance();
            cCurDate.setTime(cD);
            cCurDate.add(Calendar.DAY_OF_YEAR, 0);
            java.util.Date newCurDate = cCurDate.getTime();

            Calendar cNotificationStartVisitDate = Calendar.getInstance();
            cNotificationStartVisitDate.setTime(vD);
            cNotificationStartVisitDate.add(Calendar.DAY_OF_YEAR, -15);
            java.util.Date notificationStartDate = cNotificationStartVisitDate
                    .getTime();

            Calendar cOrignalVisitDate = Calendar.getInstance();
            cOrignalVisitDate.setTime(vD);
            cOrignalVisitDate.add(Calendar.DAY_OF_YEAR, 0);
            java.util.Date newOriDateVisitDate = cOrignalVisitDate
                    .getTime();
            totalDifference = 0;

            if (notificationStartDate.before(newCurDate)) {

                while (newOriDateVisitDate.after(newCurDate)) {
                    cOrignalVisitDate.add(Calendar.DAY_OF_YEAR, -1);
                    newOriDateVisitDate = cOrignalVisitDate.getTime();
                    totalDifference++;
                    s = "left";
                }
                while (newOriDateVisitDate.before(newCurDate)) {
                    cOrignalVisitDate.add(Calendar.DAY_OF_YEAR, +1);
                    newOriDateVisitDate = cOrignalVisitDate.getTime();
                    totalDifference++;
                    s = "ago";
                }
                countNotification++;
                listRec.add(record[2] + " Vaccine due: " + String.valueOf(totalDifference)
                        + " days " + s);

            }

        }

        for (int j = 0; j < countNotification; j++) {

            NotificationManager nm = (NotificationManager) getApplicationContext()
                    .getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
            Notification note = new Notification(R.drawable.nav_down,
                    "Vaccination ALerts!", System.currentTimeMillis());
            Intent inNotification = new Intent(this,GenUserFunction.class);
            inNotification.putExtra("user_id", userId);
            PendingIntent i =  PendingIntent.getActivity(getBaseContext(), 0,inNotification, 0);
            note.setLatestEventInfo(getApplicationContext(), "Vaccine       Due",
                    listRec.get(j), i);
            nm.notify(j, note);


        }



        // Toast.makeText(getApplicationContext(),
        // String.valueOf(listRec.size()), Toast.LENGTH_SHORT).show();

    } catch (Exception e) {
        // TODO: handle exception
        System.out.println(e.getMessage());

    }




    // Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();

    // Note: You can start a new thread and use it for long background
    // processing from here.
}





@Override
public void onDestroy() {


enter code here
    super.onDestroy();

    // Toast.makeText(this, "MyService Stopped", Toast.LENGTH_LONG).show();
    // Log.d(TAG, "onDestroy");
}
   }