我只是使用的服務,使像chathead,這是我的結果Android上運行的類
,但只有我有兩個問題
第一段時間我的服務被殺我注意到這是在弱設備,所以我怎麼能防止它在同一時間殺死Facebook的使者從未殺死
秒我的課動畫不順利我想我必須在新線程上運行該課
xxx = new classanimation (mContext);
我想這
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
xxx = new classanimation (mContext);
}
});
,但我看到了同樣的沒有什麼不同
,這是我的服務代碼
public class MyCustomService extends Service {
private volatile HandlerThread mHandlerThread;
private ServiceHandler mServiceHandler;
private static Context mContext;
Handler mHandler;
IBinder mBinder = new LocalBinder();
public static Socket client;
public classanimation xxx;
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
public class LocalBinder extends Binder {
public MyCustomService getServerInstance() {
return MyCustomService.this;
}
}
private final class ServiceHandler extends Handler {
public ServiceHandler(Looper looper) {
super(looper);
}
// Define how to handle any incoming messages here
@Override
public void handleMessage(Message message) {
// ...
// When needed, stop the service with
// stopSelf();
}
}
public void onCreate() {
super.onCreate();
this.mContext = this;
xxx= new classanimation(mContext); //class i run it but its not smooth
mHandler = new Handler(Looper.getMainLooper());
// An Android handler thread internally operates on a looper.
mHandlerThread = new HandlerThread("MyCustomService.HandlerThread");
mHandlerThread.start();
// An Android service handler is a handler running on a specific background thread.
mServiceHandler = new ServiceHandler(mHandlerThread.getLooper());
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Send empty message to background thread
mServiceHandler.sendEmptyMessageDelayed(0, 500);
// or run code in background
mServiceHandler.post(new Runnable() {
@Override
public void run() {
// Do something here in background!
SessionManager session = new SessionManager(mContext);
// If desired, stop the service
//stopSelf();
}
});
// Keep service around "sticky"
return START_STICKY;
}
@Override
public void onDestroy() {
// Cleanup service before destruction
mHandlerThread.quit();
}
}
感謝回覆我會盡力的:)仍然順利動畫的問題 –