Thursday 15 July 2010

android - Service gets killed in Jelly Bean -


I'm trying to bring the name of the application when it hits the foreground, by running it a background service Completed in which I have implemented Runnabal to run every other service. It is working fine in all the OS except Jelly Bean. My service is killed. I know that if an app consumes more RAM then it kills the available background services to manage the required location. For example high resolution games but I will lose data. I implemented foreground services. Its work is fine. I doubt that, does this effect do any kind of functionality or battery consumption? Is there any other method than the foreground ??

This is the service that I have made to the foreground.

  @Override public int onStartCommand (intended intent, int flags, int StartId) {ReceiverRunning = true; Context = this; Intent1 = new intent (this, component selector class); Pending pending index = pending IT activation (this, 1, intent 1, 0); Notification mNotification = New Notification (R.drawable.ic_launcher, "BackgroundApp", System.currentTimeMillis ()); MNotification.setLatestEventInfo (this, "batteryjays", "click to open for app", pending indent); MNotification.flags = mNotification.flags | Notification FLAG_ONGOING_EVENT; StartForeground (1000, mNotification); // Start service if not started (! ForegroundApp.isRunning == true) {context.startService (new intent (context, brightness class)); } Boolean has_tele = getPackageManager (). Hasistformer (PackageManager.FEATURE_TELEPHONY); If (has_tele == true) {TelephonyManager teleman = (TelephonyManager) getBaseContext () .getSystemService (context.TELEPHONY_SERVICE); If (Teleman! = Faucet) Device ID = teleman.getDeviceId (); } UId = deviceInfo (); {NetworkInfo info = (NetworkInfo) (Try Connectivity Manager) Reference. If (Info! = Null) {Log D. ("WifiRun", "Network Available"); Connectivity Manager ConMan = (Connectivity Manager) Reference .getSystemService (References CONNECTIVITY_SERVICE); NetworkInfo.State WiFi = Null; If (conMan.getNetworkInfo (1) .is availability ()) wifi = conMan.getNetworkInfo (1) .getState (); if (wifi == NetworkInfo.State.CONNECTED || wifi == NetworkInfo.State.CONNECTING) {wifiCheck = true; Context.startService (new intent (reference, wifi class)); log D. ("WifiRun", "wifiCheck:" + wifi check);} Other {Log D. ("Wife Run", "W EFi Check: "+ Wifi Check);}}} Grip (Exception E) {e.printStackTrace ();} Register for Screen On and Screen Off. IntentFilter intentFilter = New Intent Filter (); intentFilter.addAction (Intent ACTION_SCREEN_OFF); intentFilter.addAction (Intent.ACTION_SCREEN_ON); SReceiver = New Service Definition (); Register Receiver (SECV, Intent Filter); // Return Super. Start Command (Intention, Flags, Initial); Return START_STICKY; }    

I think there is no other way. You can make your service sticky (), but in this situation the service is the right way to make the foreground. Of course, your service will drain from the battery, so do not use "heavy" operation in your service.

If you provide the source code of your service, we will check that you implement all the optimal.

No comments:

Post a Comment