为什么我的服务在MOTOG second gen
和lenovo a1000
中完美运行,但没有立即在motoG
和LG 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编程的初学者,并且不会安静地了解不同手机中应用程序的不同行为。非常感谢...!