PDA

View Full Version : از بین نرفتن سرویس بعد از بستن برنامه



moh355
چهارشنبه 20 اسفند 1393, 07:23 صبح
سلام
من یک سرویس دارم وقتی برنامه باز هست مشکلی نداره کار میکنه اما وقتی برنامه بسته شد (یعنی از توی لیست recent app حذف شد) دیگه اون سرویس کار نمیکنه وقتی میرم توی setting-running برنامه هست و سرویس فعال ولی کار نمیکنه جالب اینه توی emulator کار میکنه اما روی تبلت نه .. ممنون میشم کمک کنید

کد مربوط به کلاس سرویس :‌

public class pservices extends Service {

protected void onCreate(Bundle savedInstanceState) {
Toast.makeText(this, "Service created.", Toast.LENGTH_LONG).show();
}

@Override
public IBinder onBind(Intent intent) {
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this, "Service Started.", Toast.LENGTH_LONG).show();
return START_STICKY;

}
@Override
public void onDestroy() {

Toast.makeText(this, "Service Destroyed.", Toast.LENGTH_LONG).show();

} }




manifest :

<service
android:name=".pservices"
android:enabled="true"
android:icon="@drawable/ic_launcher"
android:process=":my_process" >
</service>


اجرای سرویس

startService(new Intent(MainActivity.this,pservices.class));