我的应用程序上有一个分享按钮。单击共享按钮时,将打开一个共享对话框,其中包含共享选项列表。问题是当我决定不想分享(对话框打开时)并按下手机上的后退按钮时,应用程序关闭......我该如何解决这个问题???我看不到问题
share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
dbControl = new DatabaseControl(ScoreMenu.this);
dbControl.open();
score = dbControl.fetchBestTime();
dbControl.close();
share(score);
}
});
}
public void share(String score){
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "");
shareIntent.putExtra(Intent.EXTRA_TEXT, "");
startActivity(Intent.createChooser(shareIntent, ""));
}
@Override
public void onBackPressed() {
Intent goToMainScreen = new Intent(ScoreMenu.this, MainActivity.class);
if (android.os.Build.VERSION.SDK_INT >= 16) {
// Start activity with a custom animation
Bundle bundle_animation = ActivityOptions.makeCustomAnimation(ScoreMenu.this, R.anim.slide_in_right, R.anim.slide_out_left).toBundle();
startActivity(goToMainScreen, bundle_animation);
}
else {
startActivity(goToMainScreen);
}
}
希望你能帮助...