@Override protected void onCreate(Bundle savedInstanceState) { Log.d(LOG_TAG, "OnCreate"); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SaveLoadSettings.initialization(getApplicationContext()); startTrackingButton = (Button) findViewById(R.id.startTrackingButton); stopTrackingButton = (Button) findViewById(R.id.stopTrackingButton); showHelpButton = (Button) findViewById(R.id.helpButton); carNumEditText = (EditText) findViewById(R.id.carNumbEditText); carNumEditText.setText(SaveLoadSettings.getCarNumb()); View.OnClickListener onClickListener = new View.OnClickListener() { @Override public void onClick(View v) { switch (v.getId()) { case R.id.startTrackingButton: if (!SaveLoadSettings.loadValueOfTracking()) { if (carNumEditText.length() != 0) { SaveLoadSettings.startTracking(); SaveLoadSettings.setCarNumbTag(carNumEditText.getText().toString()); startService(new Intent(getApplicationContext(), GpsService.class)); // Toast.makeText(getApplicationContext(),getApplicationContext().getString(R.string.serviceEnabled),Toast.LENGTH_SHORT).show(); } else { Toast.makeText( getApplicationContext(), getApplicationContext().getString(R.string.carNumbEditTextEmpty), Toast.LENGTH_SHORT) .show(); } } else { Toast.makeText( getApplicationContext(), getApplicationContext().getString(R.string.serviceEnabledError), Toast.LENGTH_SHORT) .show(); } break; case R.id.stopTrackingButton: if (SaveLoadSettings.loadValueOfTracking()) { SaveLoadSettings.stopTracking(); stopService(new Intent(getApplicationContext(), GpsService.class)); Toast.makeText( getApplicationContext(), getApplicationContext().getString(R.string.serviceDisabled), Toast.LENGTH_SHORT) .show(); } break; case R.id.helpButton: showHelp(); break; } } }; startTrackingButton.setOnClickListener(onClickListener); stopTrackingButton.setOnClickListener(onClickListener); showHelpButton.setOnClickListener(onClickListener); }
@Override public void onReceive(Context context, Intent intent) { Log.d("BroadcastReceiver", "onReceive"); SaveLoadSettings.initialization(context); if (SaveLoadSettings.loadValueOfTracking()) { Log.d("BroadcastReceiver", "startService"); context.startService(new Intent(context, GpsService.class)); } }