Je suis nouveau à studio android et je développe une application basée sur la localisation. Ici, j'ai besoin de fermer l'application à une certaine instance, j'ai donc appelé le finish(); fonction et a tué le processus OnDestroy()Application Android s'écraser une fois sur deux dans lolipop seulement
Problème: Tout fonctionne bien dans Android 4.4 (KitKat), mais les accidents dans Lolipop (tombe en panne à la deuxième fois d'ouvrir l'application après l'installation)
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");
}
}
);
}
Publiez vos journaux de plantage, qui devraient avoir des informations sur les plantages ... – Aditya
Pourquoi utilisez-vous même 'Process.killProcess (Process.myPid());'. 'finish()' ferme lui-même l'activité. – Rohit5k2
Je ne sais pas pourquoi cela ne fonctionne pas, mais vous pouvez essayer d'appeler 'System.exit (0)' à la place ce qui est une bonne façon de le fermer –