I'm new to Android studio and i'm developing one location based app. Here, I need to close the app at some instance,so I called the finish(); function and killed the process in onDestroy()
Problem: Everything works fine in android 4.4(Kitkat) but crashes in Lollipop (Crashes at the second time of opening the app after install)
public void onClick(){
finish();
}
@Override //------------after the finish(); called---//
protected void onDestroy() {
Process.killProcess(Process.myPid());
super.onDestroy();
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
@Override
protected void onPause() {
super.onPause();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
from = (EditText) findViewById(R.id.from);
to = (EditText) findViewById(R.id.to);
go = (Button) findViewById(R.id.go);
resulted = (TextView) findViewById(R.id.result);
time = (TextView) findViewById(R.id.time1);
button = (Button) findViewById(R.id.button);
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
pb = (ProgressBar) findViewById(R.id.progressBar1);
pb.setVisibility(View.INVISIBLE);
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
go.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
str_from1=from.getText().toString();
str_to1=to.getText().toString();
str_from1 = str_from1.replaceAll("[^\\w]+", "+");
str_to1 = str_to1.replaceAll("[^\\w]+", "+");
new JSONTask().execute("https://maps.googleapis.com/maps/api/distancematrix/json?origins=" + str_from1 + "&destinations=" + str_to1 + "&mode=driving&language=fr-FR&key=API KEY");
}
}
);
}