से बाहर निकलता हूं तो एंड्रॉइड सेवा बंद हो जाती है मेरे पास एक सेवा के साथ एक आवेदन है। सेवा विधि पर मुख्य गतिविधि में ऐप द्वारा सेवा शुरू की जाती है। मेरी समस्या तब होती है जब मैं एप्लिकेशन से बाहर निकलता हूं: सेवा बंद हो जाती है और कभी-कभी तुरंत पुनरारंभ होती है, कभी-कभी हाल ही में पुन: प्रारंभ होती है। मैंने संस्करण 4.1.2 और संस्करण 2.3.6 में परीक्षण किया। सेवा संस्करण 2.3.6 में फिर से नहीं है। क्या मेरा दृष्टिकोण गलत है? स्टॉप के बीच और समय को पुनरारंभ करने के दौरान, कॉल जो अवरुद्ध होना चाहिए आ सकता है। ऐप बाहर निकलने पर सेवा को रोकने का कोई तरीका नहीं है? नोट: मैं रिमोट सेवा का उपयोग नहीं कर सकता।जब मैं एप्लिकेशन
मैंने सेवा के लिए प्रारंभिक भूमि जोड़ा लेकिन एक ही समस्या। जब मैं अनुप्रयोग से बाहर सेवा बंद कर दिया और संस्करण 2.3.3 पुनः आरंभ नहीं भी मैं देख notification.But phoneStateListener शून्य मान लेता है मैं कैसे सुनिश्चित कर सकते जब मैं अनुप्रयोग से बाहर, सेवा बंद नहीं करता है
//application main metod
@Override
protected void onCreate(Bundle savedInstanceState) {
//.....
startService(new Intent(getApplicationContext(), MyPhoneStateListener.class));
}
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
setCallListener();
setNoti();
return START_STICKY;
}
private void setCallListener()
{
try
{
if (phoneStateListener==null)
{
phoneStateListener = new StateListener();
telephonymanager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
telephonymanager.listen(phoneStateListener,PhoneStateListener.LISTEN_CALL_STATE);
}
}
catch(Exception ex)
{
}
}
निजी शून्य setNoti () {
Notification notification= new Notification(R.drawable.ic_launcher, getResources().getString(R.string.app_name), System.currentTimeMillis());
Intent main = new Intent(this, MainActivity.class);
main.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(this, getResources().getString(R.string.app_name), getResources().getStringArray(R.array.blockstate)[Sabitler.ShieldState].toString(), pendingIntent);
notification.flags |= Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_NO_CLEAR;
startForeground(123456, notification);
}
मैं बदल जहां सेवा से callstatelistener सेटिंग के रूप में धवल सोढा की सलाह दी लेकिन इस मामले को अवरुद्ध अवांछित कॉल धीमा हो में प्रसारित करने के लिए। मुझे लगता है कि प्रसारण टेलीफोनी प्रबंधक पर हर कॉलिंग शुरू होता है। नीचे प्रसारण कोड। जब मैं सेवा का उपयोग करता हूं, जब मुख्य गतिविधि बाहर निकलती है तो संस्करण 2.3.3 में बंद हो जाता है। कोई उपाय ? प्रसारण या सेवा? प्रसारण कैसे तेजी से कर सकते हैं? प्रत्येक कॉलिंग चर और ऑब्जेक्ट प्रसारण में फिर से शुरू होता है।
public class PhoneStateBroadcastReceiver extends BroadcastReceiver{
MyCustomStateListener myCustomStateListener;
TelephonyManager telephonymanager;
@Override
public void onReceive(Context context, Intent intent)
{
try
{
//Log.e("receiver1",String.valueOf(System.currentTimeMillis()));
telephonymanager = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE);
myCustomStateListener = new MyCustomStateListener(context,telephonymanager);
telephonymanager.listen(myCustomStateListener, PhoneStateListener.LISTEN_CALL_STATE);
//Log.e("receiver2",String.valueOf(System.currentTimeMillis()));
telephonymanager.listen(myCustomStateListener, PhoneStateListener.LISTEN_NONE);
}
catch(Exception ex)
{
Toast.makeText(context,"setCallListener:"+ex.toString(), Toast.LENGTH_SHORT).show();
}
}
}
आप संख्या को अवरुद्ध करना चाहते हैं ??? तो बस ब्रॉडकास्ट में इस कोड का उपयोग करें .. प्रारंभ सेवा के बजाय .. –
जब आप कहते हैं कि "सेवा बंद हो जाती है", तो आप का मतलब है कि इसकी ऑनस्ट्रोय() को आपकी गतिविधि खत्म करने के बाद बुलाया जाता है? साथ ही, जब आप "बाहर निकलें एप्लिकेशन" कहते हैं, तो क्या आपका मतलब केवल गतिविधि को खत्म करना है? – SirKnigget
हाँ System.exit (0) के साथ मुख्य गतिविधि को समाप्त करना; – user2331641