android服务在一些设备上运行不正常

时间:2015-06-16 04:52:17

标签: android service

为什么我的服务在MOTOG second genlenovo a1000中完美运行,但没有立即在motoGLG L90重新启动。我是否遗漏了某些内容?

public class CreatingServiceForL extends Service
{
Handler handler;
Hello helloObj;
ActivityManager manager;

public void checkActivity()
{
    handler = new Handler();
    ActivityRunnable  activityRunnable = new  ActivityRunnable();
    handler.postDelayed(activityRunnable, 1000);
}



@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
   //Toast.makeText(getApplicationContext(),"Service started", Toast.LENGTH_SHORT).show();
    checkActivity();
    return Service.START_STICKY;
}

@Override
public void onCreate()
{
    super.onCreate();
    manager = (ActivityManager) getApplicationContext()
            .getSystemService(Context.ACTIVITY_SERVICE);
    helloObj=new Hello(this);

    //Toast.makeText(getApplicationContext(),"Service created",    Toast.LENGTH_SHORT).show();


}

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


private class ActivityRunnable implements Runnable
{
    public void run()
    {
    //doing something
    }
}
}

在手机中它不起作用,在Setting>apps>running>myapp中,服务长时间停留在“重新启动”状态。 我仍然是Android编程的初学者,并且不会安静地了解不同手机中应用程序的不同行为。非常感谢...!

0 个答案:

没有答案