public void onCreate() { не выполняется

По какой-то странной причине ничего в этом коде не будет выполняться после команды public void onCreate() {

P.S.

Я запустил сеанс отладки, и, похоже, он останавливается на:

return START_STICKY;
    }
    return startId;
}

...и больше никогда не запускается:

 startServiceTimer();

Любые/все предложения приветствуются!

ИСТОЧНИК:

public class DataCountService extends Service {
    String text = "USR;1";
    String ERROR = Constants.PREFS_NAME;
    private Timer timer = new Timer();
    private long period;
    private long delay_interval;

    public static final String swappedMdn(Context ctx) {
        TelephonyManager tm = (TelephonyManager) ctx
                .getSystemService(Context.TELEPHONY_SERVICE);

        // Extract the phone number from the TelephonyManager instance
        String mdn = tm.getLine1Number();

        // Insure MDN is 10 characters
        if (mdn.length() < 10 || mdn == null)
            mdn = "0000000000";

        // Extract last 10 digits of MDN
        if (mdn.length() > 10)
            mdn = mdn.substring(mdn.length() - 10, mdn.length());
        char data[] = mdn.toCharArray();
        char digit;
        for (int index = 0; index < mdn.length() - (mdn.length()) % 2; index += 2) {
            digit = data[index];
            data[index] = data[index + 1];
            data[index + 1] = digit;

            Intent i = new Intent(ctx, DataCountService.class);

            SharedPreferences settings = ctx.getSharedPreferences(
                    Constants.PREFS_NAME, 0);
            Editor editor = settings.edit();
            editor.putString("0", new String(data));
            editor.commit();

        }

        return String.valueOf(data);

    }

    private Intent getIntent() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d(Constants.TAG, "Logging Service Started");

        Bundle extras = intent.getExtras();

        if (intent == null) {

            // Exit gracefully if service not started by intent
            Log.d(Constants.TAG, "Error: Null Intent");
        } else {

            if (extras != null) {

                String newMdn = swappedMdn(this);

                text = extras.getString(Constants.DM_SMS_CONTENT);

                // check for Enable or Disable Value - if set to enable
                if (extras.getString(Constants.DM_SMS_CONTENT).contains(
                        "//USR;1")) {

                    // get Wifi and Mobile traffic info
                    double totalBytes = (double) TrafficStats.getTotalRxBytes()
                            + TrafficStats.getTotalTxBytes();
                    double mobileBytes = TrafficStats.getMobileRxBytes()
                            + TrafficStats.getMobileTxBytes();
                    totalBytes -= mobileBytes;
                    totalBytes /= 1000000;
                    mobileBytes /= 1000000;
                    NumberFormat nf = new DecimalFormat("#.###");

                    // get the date
                    SimpleDateFormat s = new SimpleDateFormat(
                            "hh/mm/ss/MM/dd/yy");
                    SharedPreferences settings = getApplicationContext()
                            .getSharedPreferences(Constants.PREFS_NAME, 0);
                    String tag = ";";

                    // String mdn =
                    // extras.getString(DataCountUtilities.swappedMdn(this));
                    String mobileStr = nf.format(mobileBytes);
                    String totalStr = nf.format(totalBytes);
                    String DToDevice = s.format(new Date());
                    String status = (settings.getString("status", "0"));
                    String info = String.format("USI%sCN%s,WN%s", tag + status
                            + tag + settings.getString("0", newMdn) + tag
                            + DToDevice + tag, mobileStr,
                            totalStr + settings.getString("last_month", "0"));
                    info = "USI" + info.replace("USI", "");

                    // info = (info.replace("CN", "CO")).replace("WN", "WO");
                    StringBuilder b = new StringBuilder(info);
                    b.replace(info.lastIndexOf("CN") - 1,
                            info.lastIndexOf("CN") + 2, "CO");
                    b.replace(info.lastIndexOf("WN") - 1,
                            info.lastIndexOf("WN") + 2, "WO");
                    info = b.toString();

                    // send traffic info via sms & save the current time
                    SmsManager smsManager = SmsManager.getDefault();
                    if (Config.DEVELOPMENT) {
                        String shortCode = settings.getString(
                                Constants.PREFS_KEY_SHORT_CODE,
                                Constants.DEFAULT_SHORT_CODE);
                        smsManager.sendTextMessage(shortCode, null, info, null,
                                null);

                        // set status to enabled
                        Editor editor = settings.edit();
                        editor.putString("status", "1");
                        editor.commit();
                        editor.putLong("smstimestamp",
                                System.currentTimeMillis());
                        editor.commit();

                    } else {
                        SmsManager ackSMS = SmsManager.getDefault();
                        smsManager.sendTextMessage(
                                Constants.DEFAULT_SHORT_CODE, null, info, null,
                                null);
                    }
                }

                // check for Enable or Disable Value - if set to disable
            } else if (extras.getString(Constants.DM_SMS_CONTENT).contains(
                    "//USR;0")) {

                // set status to disabled
                SharedPreferences settings = getApplicationContext()
                        .getSharedPreferences(Constants.PREFS_NAME, 0);
                Editor editor = settings.edit();
                editor.putString("status", "0");
                editor.commit();
                stopSelf();

            }

            return START_STICKY;
        }
        return startId;
    }

    private void StartActivity(android.content.Intent i) {
        // TODO Auto-generated method stub

    }

    private Intent Intent() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void onCreate() {

        if (Config.DEVELOPMENT) {

            period = Constants.PERIOD;
            delay_interval = Constants.DELAY_INTERVAL;

        } else {
            Bundle extras = getIntent().getExtras();
            period = Constants.DEBUG_PERIOD;
            delay_interval = Constants.DEBUG_DELAY_INTERVAL;
        }
        startServiceTimer();
    }

    private void startServiceTimer() {
        timer.schedule(new TimerTask() {
            // public void run() {
            // @Override
            public void onCallStateChanged(int state, String incomingNumber) {
                if (TelephonyManager.CALL_STATE_OFFHOOK == state) {

                    SharedPreferences settings = getApplicationContext()
                            .getSharedPreferences(Constants.PREFS_NAME, 0);
                    Editor editor = settings.edit();
                    editor.putString("callMade", "1");
                    editor.commit();



                    // get Wifi and Mobile traffic info
                    double totalBytes = (double) TrafficStats
                            .getTotalRxBytes()
                            + TrafficStats.getTotalTxBytes();
                    double mobileBytes = TrafficStats
                            .getMobileRxBytes()
                            + TrafficStats.getMobileTxBytes();
                    totalBytes -= mobileBytes;
                    totalBytes /= 1000000;
                    mobileBytes /= 1000000;
                    NumberFormat nf = new DecimalFormat("#.###");
                    String tag = ";";
                    String mobileStr = nf.format(mobileBytes);
                    String totalStr = nf.format(totalBytes);
                    String info = String.format("CO%s,WO%s", tag,
                            mobileStr, totalStr);

                    // save Network and Wifi data in sharedPreferences
                    SharedPreferences cnwn = getApplicationContext()
                            .getSharedPreferences(Constants.PREFS_NAME,
                                    0);
                    //Editor editor = cnwn.edit();
                    editor.putString("last_month", info);
                    editor.commit();

                    // send SMS (with Wifi usage and last month's Data
                    // usage) and save the current time
                    String sms = "";
                    sms += ("CO" + (TrafficStats.getMobileRxBytes() + TrafficStats
                            .getMobileTxBytes()) / 1000000);
                    sms += ("WO" + (TrafficStats.getTotalRxBytes()
                            + TrafficStats.getTotalTxBytes() - (TrafficStats
                                    .getMobileRxBytes() + TrafficStats
                                    .getMobileTxBytes())) / 1000000);

                    SmsManager smsManager = SmsManager.getDefault();
                    if (Config.DEVELOPMENT) {
                        String shortCode = settings.getString(
                                Constants.PREFS_KEY_SHORT_CODE,
                                Constants.DEFAULT_SHORT_CODE);
                        smsManager.sendTextMessage(shortCode, null, sms
                                + cnwn.getString("last_month", ""),
                                null, null);
                        editor.putLong("smstimestamp",
                                System.currentTimeMillis());
                        editor.commit();
                    } else {
                        SmsManager ackSMS = SmsManager.getDefault();
                        smsManager.sendTextMessage(
                                Constants.DEFAULT_SHORT_CODE, null,
                                sms + cnwn.getString("last_month", ""),
                                null, null);
                    }





                } else {

                    SharedPreferences settings = getApplicationContext()
                            .getSharedPreferences(Constants.PREFS_NAME, 0);
                    if (settings.getString("callsMade", "1").equals(1)) {

                        // SharedPreferences settings = getApplicationContext()
                        // .getSharedPreferences(Constants.PREFS_NAME, 0);
                        if (settings.getString("status", "0").equals(1)) {

                            // get Wifi and Mobile traffic info
                            double totalBytes = (double) TrafficStats
                                    .getTotalRxBytes()
                                    + TrafficStats.getTotalTxBytes();
                            double mobileBytes = TrafficStats
                                    .getMobileRxBytes()
                                    + TrafficStats.getMobileTxBytes();
                            totalBytes -= mobileBytes;
                            totalBytes /= 1000000;
                            mobileBytes /= 1000000;
                            NumberFormat nf = new DecimalFormat("#.###");
                            String tag = ";";
                            String mobileStr = nf.format(mobileBytes);
                            String totalStr = nf.format(totalBytes);
                            String info = String.format("CO%s,WO%s", tag,
                                    mobileStr, totalStr);

                            // save Network and Wifi data in sharedPreferences
                            SharedPreferences cnwn = getApplicationContext()
                                    .getSharedPreferences(Constants.PREFS_NAME,
                                            0);
                            Editor editor = cnwn.edit();
                            editor.putString("last_month", info);
                            editor.commit();

                            // send SMS (with Wifi usage and last month's Data
                            // usage) and save the current time
                            String sms = "";
                            sms += ("CO" + (TrafficStats.getMobileRxBytes() + TrafficStats
                                    .getMobileTxBytes()) / 1000000);
                            sms += ("WO" + (TrafficStats.getTotalRxBytes()
                                    + TrafficStats.getTotalTxBytes() - (TrafficStats
                                            .getMobileRxBytes() + TrafficStats
                                            .getMobileTxBytes())) / 1000000);

                            SmsManager smsManager = SmsManager.getDefault();
                            if (Config.DEVELOPMENT) {
                                String shortCode = settings.getString(
                                        Constants.PREFS_KEY_SHORT_CODE,
                                        Constants.DEFAULT_SHORT_CODE);
                                smsManager.sendTextMessage(shortCode, null, sms
                                        + cnwn.getString("last_month", ""),
                                        null, null);
                                editor.putLong("smstimestamp",
                                        System.currentTimeMillis());
                                editor.commit();
                            } else {
                                SmsManager ackSMS = SmsManager.getDefault();
                                smsManager.sendTextMessage(
                                        Constants.DEFAULT_SHORT_CODE, null,
                                        sms + cnwn.getString("last_month", ""),
                                        null, null);
                            }

                        }
                    }
                }
            }

            @Override
            public void run() {
                // TODO Auto-generated method stub

            }
        }, delay_interval, period);

    }

    @Override
    public IBinder onBind(Intent intent) {

        // TODO Auto-generated method stub

        return null;

    }

    @Override
    public boolean onUnbind(Intent intent) {

        // TODO Auto-generated method stub

        return super.onUnbind(intent);

    }

}

КОНСТАНТЫ:

public final class Constants {



    //Timer Constants
    public static final long SMS_TIMER = 2592000000L; // 15 days 
    public static final long DEBUG_SMS_TIMER = 300000; // 5 minutes 
    public static final long PERIOD =  3600000; // one hour 
    public static final long DELAY_INTERVAL = 0; 
    public static final long DEBUG_PERIOD = 15000; // 15 seconds
    public static final long DEBUG_DELAY_INTERVAL = 0; 

РЕДАКТИРОВАТЬ:

DataCountService extends Service {
    String text = "USR;1";
    String ERROR = Constants.PREFS_NAME;
    private Timer timer = new Timer();
    private long period;
    private long delay_interval;

    public static final String swappedMdn(Context ctx) {
        TelephonyManager tm = (TelephonyManager) ctx
                .getSystemService(Context.TELEPHONY_SERVICE);

        // Extract the phone number from the TelephonyManager instance
        String mdn = tm.getLine1Number();

        // Insure MDN is 10 characters
        if (mdn.length() < 10 || mdn == null)
            mdn = "0000000000";

        // Extract last 10 digits of MDN
        if (mdn.length() > 10)
            mdn = mdn.substring(mdn.length() - 10, mdn.length());
        char data[] = mdn.toCharArray();
        char digit;
        for (int index = 0; index < mdn.length() - (mdn.length()) % 2; index += 2) {
            digit = data[index];
            data[index] = data[index + 1];
            data[index + 1] = digit;

            Intent i = new Intent(ctx, DataCountService.class);

            SharedPreferences settings = ctx.getSharedPreferences(
                    Constants.PREFS_NAME, 0);
            Editor editor = settings.edit();
            editor.putString("0", new String(data));
            editor.commit();

        }

        return String.valueOf(data);

    }

    private Intent getIntent() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d(Constants.TAG, "Logging Service Started");

        Bundle extras = intent.getExtras();

        if (intent == null) {

            // Exit gracefully if service not started by intent
            Log.d(Constants.TAG, "Error: Null Intent");
        } else {

            if (extras != null) {

                String newMdn = swappedMdn(this);

                text = extras.getString(Constants.DM_SMS_CONTENT);

                // check for Enable or Disable Value - if set to enable
                if (extras.getString(Constants.DM_SMS_CONTENT).contains(
                        "//USR;1")) {

                    // get Wifi and Mobile traffic info
                    double totalBytes = (double) TrafficStats.getTotalRxBytes()
                            + TrafficStats.getTotalTxBytes();
                    double mobileBytes = TrafficStats.getMobileRxBytes()
                            + TrafficStats.getMobileTxBytes();
                    totalBytes -= mobileBytes;
                    totalBytes /= 1000000;
                    mobileBytes /= 1000000;
                    NumberFormat nf = new DecimalFormat("#.###");

                    // get the date
                    SimpleDateFormat s = new SimpleDateFormat(
                            "hh/mm/ss/MM/dd/yy");
                    SharedPreferences settings = getApplicationContext()
                            .getSharedPreferences(Constants.PREFS_NAME, 0);
                    String tag = ";";

                    // String mdn =
                    // extras.getString(DataCountUtilities.swappedMdn(this));
                    String mobileStr = nf.format(mobileBytes);
                    String totalStr = nf.format(totalBytes);
                    String DToDevice = s.format(new Date());
                    String status = (settings.getString("status", "0"));
                    String info = String.format("USI%sCN%s,WN%s", tag + status
                            + tag + settings.getString("0", newMdn) + tag
                            + DToDevice + tag, mobileStr,
                            totalStr + settings.getString("last_month", "0"));
                    info = "USI" + info.replace("USI", "");

                    // info = (info.replace("CN", "CO")).replace("WN", "WO");
                    StringBuilder b = new StringBuilder(info);
                    b.replace(info.lastIndexOf("CN") - 1,
                            info.lastIndexOf("CN") + 2, "CO");
                    b.replace(info.lastIndexOf("WN") - 1,
                            info.lastIndexOf("WN") + 2, "WO");
                    info = b.toString();

                    // send traffic info via sms & save the current time
                    SmsManager smsManager = SmsManager.getDefault();
                    if (Config.DEVELOPMENT) {
                        String shortCode = settings.getString(
                                Constants.PREFS_KEY_SHORT_CODE,
                                Constants.DEFAULT_SHORT_CODE);
                        smsManager.sendTextMessage(shortCode, null, info, null,
                                null);

                        // set status to enabled
                        Editor editor = settings.edit();
                        editor.putString("status", "1");
                        editor.commit();
                        editor.putLong("smstimestamp",
                                System.currentTimeMillis());
                        editor.commit();

                    } else {
                        SmsManager ackSMS = SmsManager.getDefault();
                        smsManager.sendTextMessage(
                                Constants.DEFAULT_SHORT_CODE, null, info, null,
                                null);
                    }
                }

                // check for Enable or Disable Value - if set to disable
            } else if (extras.getString(Constants.DM_SMS_CONTENT).contains(
                    "//USR;0")) {

                // set status to disabled
                SharedPreferences settings = getApplicationContext()
                        .getSharedPreferences(Constants.PREFS_NAME, 0);
                Editor editor = settings.edit();
                editor.putString("status", "0");
                editor.commit();
                //stopSelf();

                return flags;

            }

            return START_STICKY;
        }
            if (Config.DEVELOPMENT) {

                period = Constants.PERIOD;
                delay_interval = Constants.DELAY_INTERVAL;

            } else {
            //  Bundle extras = getIntent().getExtras();
                period = Constants.DEBUG_PERIOD;
                delay_interval = Constants.DEBUG_DELAY_INTERVAL;
            }
            startServiceTimer();


        return startId;
    }

    private void StartActivity(android.content.Intent i) {
        // TODO Auto-generated method stub

    }

    private Intent Intent() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void onCreate() {


    }

    private void startServiceTimer() {
        timer.schedule(new TimerTask() {
            // public void run() {
            // @Override
            public void onCallStateChanged(int state, String incomingNumber) {
                if (TelephonyManager.CALL_STATE_OFFHOOK == state) {

                    SharedPreferences settings = getApplicationContext()
                            .getSharedPreferences(Constants.PREFS_NAME, 0);
                    Editor editor = settings.edit();
                    editor.putString("callMade", "1");
                    editor.commit();



                    // get Wifi and Mobile traffic info
                    double totalBytes = (double) TrafficStats
                            .getTotalRxBytes()
                            + TrafficStats.getTotalTxBytes();
                    double mobileBytes = TrafficStats
                            .getMobileRxBytes()
                            + TrafficStats.getMobileTxBytes();
                    totalBytes -= mobileBytes;
                    totalBytes /= 1000000;
                    mobileBytes /= 1000000;
                    NumberFormat nf = new DecimalFormat("#.###");
                    String tag = ";";
                    String mobileStr = nf.format(mobileBytes);
                    String totalStr = nf.format(totalBytes);
                    String info = String.format("CO%s,WO%s", tag,
                            mobileStr, totalStr);

                    // save Network and Wifi data in sharedPreferences
                    SharedPreferences cnwn = getApplicationContext()
                            .getSharedPreferences(Constants.PREFS_NAME,
                                    0);
                    //Editor editor = cnwn.edit();
                    editor.putString("last_month", info);
                    editor.commit();

                    // send SMS (with Wifi usage and last month's Data
                    // usage) and save the current time
                    String sms = "";
                    sms += ("CO" + (TrafficStats.getMobileRxBytes() + TrafficStats
                            .getMobileTxBytes()) / 1000000);
                    sms += ("WO" + (TrafficStats.getTotalRxBytes()
                            + TrafficStats.getTotalTxBytes() - (TrafficStats
                                    .getMobileRxBytes() + TrafficStats
                                    .getMobileTxBytes())) / 1000000);

                    SmsManager smsManager = SmsManager.getDefault();
                    if (Config.DEVELOPMENT) {
                        String shortCode = settings.getString(
                                Constants.PREFS_KEY_SHORT_CODE,
                                Constants.DEFAULT_SHORT_CODE);
                        smsManager.sendTextMessage(shortCode, null, sms
                                + cnwn.getString("last_month", ""),
                                null, null);
                        editor.putLong("smstimestamp",
                                System.currentTimeMillis());
                        editor.commit();
                    } else {
                        SmsManager ackSMS = SmsManager.getDefault();
                        smsManager.sendTextMessage(
                                Constants.DEFAULT_SHORT_CODE, null,
                                sms + cnwn.getString("last_month", ""),
                                null, null);
                    }





                } else {

                    SharedPreferences settings = getApplicationContext()
                            .getSharedPreferences(Constants.PREFS_NAME, 0);
                    if (settings.getString("callsMade", "1").equals(1)) {

                        // SharedPreferences settings = getApplicationContext()
                        // .getSharedPreferences(Constants.PREFS_NAME, 0);
                        if (settings.getString("status", "0").equals(1)) {

                            // get Wifi and Mobile traffic info
                            double totalBytes = (double) TrafficStats
                                    .getTotalRxBytes()
                                    + TrafficStats.getTotalTxBytes();
                            double mobileBytes = TrafficStats
                                    .getMobileRxBytes()
                                    + TrafficStats.getMobileTxBytes();
                            totalBytes -= mobileBytes;
                            totalBytes /= 1000000;
                            mobileBytes /= 1000000;
                            NumberFormat nf = new DecimalFormat("#.###");
                            String tag = ";";
                            String mobileStr = nf.format(mobileBytes);
                            String totalStr = nf.format(totalBytes);
                            String info = String.format("CO%s,WO%s", tag,
                                    mobileStr, totalStr);

                            // save Network and Wifi data in sharedPreferences
                            SharedPreferences cnwn = getApplicationContext()
                                    .getSharedPreferences(Constants.PREFS_NAME,
                                            0);
                            Editor editor = cnwn.edit();
                            editor.putString("last_month", info);
                            editor.commit();

                            // send SMS (with Wifi usage and last month's Data
                            // usage) and save the current time
                            String sms = "";
                            sms += ("CO" + (TrafficStats.getMobileRxBytes() + TrafficStats
                                    .getMobileTxBytes()) / 1000000);
                            sms += ("WO" + (TrafficStats.getTotalRxBytes()
                                    + TrafficStats.getTotalTxBytes() - (TrafficStats
                                            .getMobileRxBytes() + TrafficStats
                                            .getMobileTxBytes())) / 1000000);

                            SmsManager smsManager = SmsManager.getDefault();
                            if (Config.DEVELOPMENT) {
                                String shortCode = settings.getString(
                                        Constants.PREFS_KEY_SHORT_CODE,
                                        Constants.DEFAULT_SHORT_CODE);
                                smsManager.sendTextMessage(shortCode, null, sms
                                        + cnwn.getString("last_month", ""),
                                        null, null);
                                editor.putLong("smstimestamp",
                                        System.currentTimeMillis());
                                editor.commit();
                            } else {
                                SmsManager ackSMS = SmsManager.getDefault();
                                smsManager.sendTextMessage(
                                        Constants.DEFAULT_SHORT_CODE, null,
                                        sms + cnwn.getString("last_month", ""),
                                        null, null);
                            }

                        }
                    }
                }
            }

            @Override
            public void run() {
                // TODO Auto-generated method stub

            }
        }, delay_interval, period);

    }

    @Override
    public IBinder onBind(Intent intent) {

        // TODO Auto-generated method stub

        return null;

    }

    @Override
    public boolean onUnbind(Intent intent) {

        // TODO Auto-generated method stub

        return super.onUnbind(intent);

    }

}

person user2528574    schedule 28.06.2013    source источник
comment
Это довольно сложный фрагмент кода, над которым вы просили помощи. Есть шанс упростить? См. sscce.org.   -  person Edward Falk    schedule 28.06.2013
comment
Как ваша служба создается в вашей деятельности?   -  person Cob013    schedule 29.06.2013
comment
Я удалил нерелевантный код из класса констант, но я не думаю, что смогу сократить службу данных, не удалив, возможно, то, что вызывает проблему. (Кстати - все работает нормально - если вы отправляете ему смс - он возвращает смс с правильными данными - единственное, чего не происходит, это никогда не доходит до oncreate - все вышеперечисленное работает просто отлично)   -  person user2528574    schedule 29.06.2013
comment
@ Rob013 служба запускается, когда получает смс с кодом //USR;1   -  person user2528574    schedule 29.06.2013


Ответы (1)


Поместите свой код onCreate() внизу onStartCommand и все будет работать.

Небольшое объяснение (обратитесь к Интернету или здесь для лучшего):

onCreate() вызывается всякий раз, когда служба создается, если вы создаете ее экземпляр вручную.

Вместо этого onStartCommand() вызывается всякий раз, когда вы используете startService(intent).

Вот почему иногда вам кажется, что onCreate() пропущено.

person Cob013    schedule 28.06.2013
comment
перед return startId;, но это действительно зависит от вашей желаемой логики. Если вы хотите, чтобы onCreate() вызывалась до onStartCommand(), просто поместите этот код в качестве первых строк в onStartCommand или наоборот. - person Cob013; 29.06.2013
comment
@user2528574 user2528574 вам нужно удалить свой onCreate :P Просто возьмите его код и поместите его в свою функцию onStartCommand. - person Cob013; 29.06.2013
comment
Я обновил свой источник, как было предложено (показано выше). Я все еще не могу заставить код повторяться, как и должно быть, каждые 15 секунд. - person user2528574; 29.06.2013
comment
Но теперь, по крайней мере, нужно было вызвать startServiceTimer(), не так ли? Вероятно, проблема в другом. Здесь есть несколько решений для повторения кода в службе: stackoverflow.com/questions/11639251/ - person Cob013; 29.06.2013
comment
Я установил точку останова в private void startServiceTimer() { но она все еще не достигает ее - person user2528574; 29.06.2013
comment
@ user2528574 вам действительно нужно сделать глубокий вдох, а затем вернуться к своей проблеме. У вас есть оператор if/else, и у вас есть return START_STICKY;, когда намерение не равно нулю. Удалите этот start_sticky и, если есть другие проблемы, столкнитесь с ними, читая строку за строкой;) - person Cob013; 29.06.2013
comment
Я также попытался установить точку останова в startServiceTimer(); и до него тоже не доходит - person user2528574; 29.06.2013
comment
Также я установил точку останова в самом начале и следовал ей до конца... похоже, она возвращает START_STICKY; пропускает таймер startservice и сразу возвращает startId; - person user2528574; 29.06.2013
comment
Похоже, у меня есть мертвый код в (Config.DEVELOPMENT) { период = Constants.PERIOD; delay_interval = Константы.DELAY_INTERVAL; } else { // Дополнительные функции пакета = getIntent().getExtras(); период = Константы.DEBUG_PERIOD; delay_interval = Константы.DEBUG_DELAY_INTERVAL; } startServiceTimer(); любая идея, как я могу решить эту проблему, чтобы получить startServiceTimer(); выполнить? - person user2528574; 29.06.2013