每当我尝试通过按两次后退按钮退出应用程序时,就会出现启动屏幕,并且该屏幕冻结,直到再次按下后退按钮。因此,我需要按三下返回按钮才能退出我的应用。请帮助我仅按两次后退按钮退出应用程序。
项目中的Java代码如下:
public void onBackPressed()
{
if (doubleBackToExitPressedOnce)
{
super.onBackPressed();
MapsActivity.this.finish();
}
this.doubleBackToExitPressedOnce = true;
Toast.makeText(this, "Please click Back again to exit", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable()
{
@Override
public void run()
{
doubleBackToExitPressedOnce = false;
}
}, 2000);
}
我的启动画面代码如下:
public class SplashScreen extends AppCompatActivity {
ImageView logoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
Animation anim1 = AnimationUtils.loadAnimation(this,R.anim.anim_down);
logoView = findViewById(R.id.logoview);
logoView.setAnimation(anim1);
Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
@Override
public void run()
{
Intent next_scrn = new Intent(SplashScreen.this,MapsActivity.class);
startActivity(next_scrn);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
}
},2500);
}
}
答案 0 :(得分:1)
您应该在开始新活动后完成splashActivity,所以请使用:
var r *ReqJSON
err := json.Unmarshal(data, &r)
// Check error
u := unwrap(r) // Here we have the user
答案 1 :(得分:1)
在以下代码后添加finish();
。
Intent next_scrn = new Intent(SplashScreen.this,MapsActivity.class);
startActivity(next_scrn);
答案 2 :(得分:1)
您必须完成()启动画面,如下所示,而不是在BackPress工作上的条件
fileDataList.stream()
.filter(distinctByKey(x -> Arrays.asList(x.get("name"), x.get("age")))
.collect(Collectors.toList());