应用程序在Android 4.1.2中关闭

时间:2013-09-22 01:44:57

标签: android debugging

我的应用程序几乎在所有Android设备上运行(在Galaxy Young上,语音不起作用),但在Android 4.1.2上,应用程序在一段时间后关闭。这是正常的吗?如何保持我的应用程序运行?我用线程启动服务,我把它放在:

public class Servicechecker extends Service
{
    Thread th1;
    Globals g = Globals.getInstance();
    @Override
    public IBinder onBind(Intent arg0) {
        // TODO Auto-generated method stub
        return null;
    }
    @Override
    public void onCreate()
    {
        Log.d("DEBUG","Servicio Creado");
        g.setservicio(true);
        hilo();
    }
    public void hilo()
    {
        Log.d("DEBUG","en hilo");
        th1= new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    try {
                        Thread.sleep(100000000);
                        Log.d("Debug","Servicio");
                        /*if(g.getsms())
                        {
                            Intent intenttwo = new Intent(getApplicationContext(), Sms.class);
                            intenttwo.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                            g.setnumero("2721700311");
                            g.setmensaje("Body");
                            startActivity(intenttwo);
                        }*/
                        System.gc();
                        } catch (InterruptedException e) {
                        Log.d("DEBUG","I1: " + e.toString());
                        return;
                    }
                }
            }
        });
        th1.start();
    }
    protected void sendnotification (String title, String message) {
        String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
        int icon = R.drawable.ic_launcher;
        CharSequence tickerText = message;
        long when = System.currentTimeMillis();
        Notification notification = new Notification(icon, tickerText, when);
        Context context = getApplicationContext();
        CharSequence contentTitle = title;
        CharSequence contentText = message;
        Intent notificationIntent = new Intent(this, ProxSenET.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
        notification.flags = Notification.FLAG_AUTO_CANCEL;
        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
        mNotificationManager.notify(1, notification);
        Log.d("DEBUG","Paso not");
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        g.setservicio(false);
        System.gc();
    }
}

但它仍然关闭。

0 个答案:

没有答案