I have developed a app which working properly. In background it contains a service which is the core part of this app. The service detects the power button press and does necessary action. The service is also built with auto startup at phone restart.

The problem is, however occurring rarely, (fully random) while running at background it is getting UNFORTUNATELY STOPPED. This app is meant to run continuously forever without user interaction. Therefore the unfortunate stopping is not allowed.

From some thread I came to know that CLEAR CACHE and DATA might help to resolve this. I can't clear the data because it contains important information. What I did is clearing the cache periodically through code. But still I am facing the same problem.

Can anybody let me know what could be the possible reason and how to handle it. Below is my code for the service. I can get the LogCat because it is crashing randomly after running some hours.

public class UpdateService extends Service implements LocationListener
{
    private static final int NOTIFY_ME_ID=1340,NOTIFY_ME_ID1=1338,NOTIFY_ME_ID_Loc=1339; 
    public static SharedPreferences mySharedPrefs;
    static BroadcastReceiver mReceiver;
    TextView display_counter;
    int counter; 
    boolean timer_runing=false;
    private CountDownTimer countDownTimer, mintimer, start_timer;
    SmsManager sms;
    LocationManager mLocationManager,mLocationManagerGps;
    Location mLocation;
    String locationprovider, locationproviderGps;
    Vibrator v;
    static Boolean flag = false;
    String message = "Help !\nI am in danger."+"\nPlz track my location in this link:\n";
    String from;
    String myLocation;
    NotificationManager mgr, mgr_gps;
    Notification note,note_gps,note_loc_ser;
    Criteria criteria;
    Intent in_gps;
    PendingIntent i_gps;

    @Override
    public void onCreate()
    {
        super.onCreate();    
        // register receiver that handles screen on and screen off logic

        v = (Vibrator)this.getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
        mySharedPrefs = getSharedPreferences("myphone", 0);
        IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
        filter.addAction(Intent.ACTION_SCREEN_OFF);
        filter.addAction(Intent.ACTION_BOOT_COMPLETED);
        mReceiver = new Receiver();
        registerReceiver(mReceiver, filter);
        countDownTimer = new MyCountDownTimer( 1000, 100);
        mintimer = new MyCountDownTimer2 ( 120000, 1000);
        start_timer = new MyCountDownTimer2 ( 20000, 1000);

        mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        //mLocationManagerGps = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setPowerRequirement(Criteria.POWER_LOW);
        //locationprovider = mLocationManager.getBestProvider(criteria,true);

        locationprovider = mLocationManager.NETWORK_PROVIDER;

        mLocationManager.requestLocationUpdates(locationprovider,50000,(float) 120.0, this);        

        mLocation = mLocationManager.getLastKnownLocation(locationprovider);

        // notification to enable GPS

        mgr_gps=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        note_gps=new Notification(R.drawable.frightenedgirl,"SAVE ME: Enable GPS",System.currentTimeMillis());
        note_gps.defaults |= Notification.DEFAULT_LIGHTS;
        note_gps.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;
        in_gps = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        i_gps = PendingIntent.getActivity(getApplicationContext(), 0, in_gps,0);
        note_gps.setLatestEventInfo(getBaseContext(), "SAVE ME: Enable GPS","Enable GPS for best performance", i_gps);

      // notification to open location settings
        note_loc_ser=new Notification(R.drawable.frightenedgirl,"SAVE ME:Enable Location Provider",System.currentTimeMillis());
        note_loc_ser.defaults |= Notification.DEFAULT_LIGHTS;
        note_loc_ser.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;
        note_loc_ser.setLatestEventInfo(getBaseContext(), "SAVE ME:Enable Location Service","Atleast Wireless Networks for location", i_gps);

        sms=SmsManager.getDefault();
    }

    @Override
    public void onDestroy()
    {
        unregisterReceiver(mReceiver);
        //Log.i("onDestroy Reciever", "Called");

        super.onDestroy();
    }

    @SuppressLint("NewApi")
    @Override
    public void onStart(Intent intent, int startId)
    {
        boolean screenOn = intent.getBooleanExtra("screen_state", false);
        String from = intent.getStringExtra("from");

        deleteCache(getApplicationContext());

        if(startId==2 || (startId%100)==0)
        {
            if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) );
            else
                mgr_gps.notify(NOTIFY_ME_ID_Loc, note_loc_ser);     
        }

    if(startId==1){
        counter=0;

        Toast.makeText(getApplicationContext(),"Protection Started",Toast.LENGTH_LONG).show();
    }
    else {

        //Notofication for memory cleared
        if (from.equals("receiver")){
        if ((mySharedPrefs.getString("ph1", "").equals("")) && (mySharedPrefs.getString("ph2", "").equals("")) && (mySharedPrefs.getString("ph3", "").equals("")) && (mySharedPrefs.getString("ph4", "").equals("")) && (mySharedPrefs.getString("ph5", "").equals(""))) {

            final NotificationManager mgr1=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
            Notification note1=new Notification(R.drawable.frightenedgirl,"SAVE ME: Phone numbers found erased",System.currentTimeMillis());
            note1.defaults |= Notification.DEFAULT_LIGHTS;
            note1.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;
            PendingIntent i = PendingIntent.getActivity(getBaseContext(), 0,new Intent(getBaseContext(), MainActivity.class),0);
            note1.setLatestEventInfo(getBaseContext(), "SAVE ME : Numbers erased","Re setup required", i);
            mgr1.notify(NOTIFY_ME_ID1, note1);
        }
        } 


    counter=counter+1;

    if (timer_runing) 
        countDownTimer.cancel();
    countDownTimer.start();
    timer_runing=true;  




    // do ur stuff at four consequitive press

    if (counter==4){ 

        flag = true;

        mgr=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        note=new Notification(R.drawable.frightenedgirl,"SAVE ME: Close ones are being continuously notified",System.currentTimeMillis());
        note.defaults |= Notification.DEFAULT_LIGHTS;
        note.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;
        PendingIntent i = PendingIntent.getActivity(getBaseContext(), 0,new Intent(getBaseContext(), deact.class).putExtra("from","service"),0);
        note.setLatestEventInfo(getBaseContext(), "SAVE ME : Deactivate","Deactivate Continuous Notificaion", i);
        mgr.notify(NOTIFY_ME_ID, note);

        v.vibrate(1000);


        start_timer.start();

   }

}
}

public void notifi() {
    // *********** SMS Notofication ************//


    mintimer.cancel();

    if (flag == true){  

    v.vibrate(500);

    mgr.notify(NOTIFY_ME_ID, note);
    if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) );
    else
        mgr_gps.notify(NOTIFY_ME_ID_Loc, note_gps);


    if (mLocation != null)
        myLocation = "http://maps.google.com/?q="+mLocation.getLatitude()+","+mLocation.getLongitude();
    else
        myLocation = "Currently Not available";



    if (!mySharedPrefs.getString("ph1", "").equals("")) {
        sms.sendTextMessage(mySharedPrefs.getString("ph1", ""), null, message+myLocation+"\n"+mySharedPrefs.getString("name", "") , null, null);
    }

    if (!mySharedPrefs.getString("ph2", "").equals("")) {
        sms.sendTextMessage(mySharedPrefs.getString("ph2", ""), null, message+myLocation+"\n"+mySharedPrefs.getString("name", ""), null, null);

        }

     if (!mySharedPrefs.getString("ph3", "").equals("")) {
        sms.sendTextMessage(mySharedPrefs.getString("ph3", ""), null, message+myLocation+"\n"+mySharedPrefs.getString("name", "") , null, null);

        }
    if (!mySharedPrefs.getString("ph4", "").equals("")) {
        sms.sendTextMessage(mySharedPrefs.getString("ph4", ""), null,message+myLocation+"\n"+mySharedPrefs.getString("name", "") , null, null);

        }
    if (!mySharedPrefs.getString("ph5", "").equals("")) {
        sms.sendTextMessage(mySharedPrefs.getString("ph5", ""), null,message+myLocation+"\n"+mySharedPrefs.getString("name", "") , null, null);

        }



    //Toast.makeText(getApplicationContext(), Integer.toString(startId).concat("Informed")+mySharedPrefs.getString("ph1", ""),Toast.LENGTH_LONG).show();



    if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) ){
    locationprovider = mLocationManager.getBestProvider(criteria,true);
    mLocationManager.requestLocationUpdates(locationprovider,5000,(float) 5.0, this);
    }

    //Toast.makeText(getApplicationContext(), locationprovider ,Toast.LENGTH_LONG).show();
    Toast.makeText(getApplicationContext(), "Close ones are being informed" ,Toast.LENGTH_LONG).show();
    mintimer.start();
    //Toast.makeText(getApplicationContext(),"True,timer start" ,Toast.LENGTH_LONG).show();
    } 
    else{
        counter = 0;
    }
}



@Override
public IBinder onBind(Intent arg0) {
    // TODO Auto-generated method stub
    return null;
}


//  Count down timer class


 public class MyCountDownTimer extends CountDownTimer {
      public MyCountDownTimer(long startTime, long interval) {
       super(startTime, interval);
      }

      @Override
      public void onFinish() {
       counter=0;
          //text.setText("Time's up!");
      }

      @Override
      public void onTick(long millisUntilFinished) {
       //text.setText("" + millisUntilFinished / 1000);
      }
     }

 public class MyCountDownTimer2 extends CountDownTimer {
      public MyCountDownTimer2(long startTime, long interval) {
       super(startTime, interval);
      }

      @Override
      public void onFinish() {
          notifi();
     }

      @Override
      public void onTick(long millisUntilFinished) {

      }
     }


@Override
public void onLocationChanged(Location location) {
    // TODO Auto-generated method stub
    //Toast.makeText(getApplicationContext(), "location updated" ,Toast.LENGTH_LONG).show();
    mLocation = location;

}
@Override
public void onProviderDisabled(String arg0) {
    // TODO Auto-generated method stub

}
@Override
public void onProviderEnabled(String arg0) {
    // TODO Auto-generated method stub

}
@Override
public void onStatusChanged(String provider, int arg1, Bundle arg2) {
    //Toast.makeText(getApplicationContext(), provider+"is being used for location" ,Toast.LENGTH_LONG).show();

}

public void deleteCache(Context context) {
    //Toast.makeText(getApplicationContext(),"may be delet",Toast.LENGTH_LONG).show();
    try {
        File dir = context.getCacheDir();
        if (dir != null && dir.isDirectory()) {
            deleteDir(dir);
            //Toast.makeText(getApplicationContext(),"deleted",Toast.LENGTH_LONG).show();
        }
    } catch (Exception e) {}
}

public static boolean deleteDir(File dir) {
    if (dir != null && dir.isDirectory()) {
        String[] children = dir.list();
        for (int i = 0; i < children.length; i++) {
            boolean success = deleteDir(new File(dir, children[i]));
            if (!success) {
                return false;
            }
        }
    }
    return dir.delete();
}

}`



Filename: chief.keef.bang.the.mixtape.pt.2mixtape2013.desspratt.Zip
Keywords: mixtape, chief, keef, desspratt, 2mixtape2013
Uploaded: 7 days ago

Download chief.keef.bang.the.mixtape.pt.2mixtape2013.desspratt.zip
Direct Link


Download

Download chief.keef.bang.the.mixtape.pt.2mixtape2013.desspratt.zip
Mediafire


Download

Download chief.keef.bang.the.mixtape.pt.2mixtape2013.desspratt.zip
Indowebster


Download

Download chief.keef.bang.the.mixtape.pt.2mixtape2013.desspratt.zip
4shared


Download

Download chief.keef.bang.the.mixtape.pt.2mixtape2013.desspratt.zip
EASY-SHARE


Download