0
我几天后,与Android服务的问题。 我从服务写了自定义类 我从线程写了自定义类。在销毁应用程序后运行自定义线程中的自定义服务
我希望我的服务在销毁程序后发送通知,一切正常,但定制类不工作后,但在停止或暂停应用程序后,我的服务工作正确。
请帮我解决这个问题。
ServiceNotification.class
import Threadcustom;
public class ServiceNotification extends Service {
@Override
public void onCreate() {
super.onCreate();
}
@Override
public int onStartCommand(final Intent intent, int flags, int startId) {
GlobalController.timerTaskService = new TimerTask() {
@Override
public void run() {
Threadcustom threadc = new Threadcustom();
threadc.setDetail("1");
threadc.start();
Threadcustom threadc1 = new Threadcustom();
threadc1.setDetail("2");
threadc1.start();
if (threadc.newMessage == 1) {
CustomNotification customNotification = new CustomNotification();
customNotification.notifiaction("my message");
}
}
};
GlobalController.timerService.schedule(GlobalController.timerTaskService, 0, 5000);
return Service.START_STICKY;
}
public void onTaskRemoved(Intent rootIntent) {
Intent restartService = new Intent(getApplicationContext(),
this.getClass());
restartService.setPackage(getPackageName());
PendingIntent restartServicePI = PendingIntent.getService(
getApplicationContext(), 1, restartService,
PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmService = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
alarmService.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 5000, restartServicePI);
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public void onRebind(Intent intent) {
super.onRebind(intent);
}
}
的manifest.xml
<receiver
android:name=".services.ServiceBootCompleteReciver"
android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
<service
android:name=".services.ServiceNotification"
android:enabled="true"
android:exported="false"
/>
Threadcustom.class
public class ThreadSms extends Thread {
@Override
public void run() {
super.run();
define my url
define http url connection get data from url then insert data to sqlite database in my application.
}
我的工作线程纠正我的服务工作,线程和发送通知,但破坏之后应用程序通知工作,但我的自定义线程没有调用,任何程序不只是崩溃所述警告
ClassLoader referenced unknown path: /data/app/app.myapp/lib/arm
ClassLoader referenced unknown path: /system/framework/tcmclient.jar
tnanks男人,我的问题消失了。 – user3750973
@ user3750973您的欢迎伙伴 –
当屏幕锁定或睡眠时,它可以工作吗?我可以在屏幕锁定或睡眠电话上工作吗? – user3750973