1

我的应用程序几乎在所有 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();
    }
}

但它仍然关闭。

4

0 回答 0