Я выполнил свое приложение, чтобы выйти, когда нажата кнопка «Назад». Когда я выхожу из приложения, я обычно получаю прерывистый выход, где отображаются последние приложения, прежде чем приложение будет правильно завершено. Что может быть причиной этой проблемы? Вот мой код.Choppy exit при нажатии на кнопку назад
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button discover,why,enterprise,business,services,office,inquire,connect;
TextView offer;
Intent p;
private static long back_pressed_time;
private static long PERIOD = 2000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
offer = (TextView)findViewById(R.id.offer);
discover = (Button) findViewById(R.id.discover_us);
why = (Button) findViewById(R.id.why_us);
enterprise = (Button) findViewById(R.id.enterprise_soln);
business = (Button) findViewById(R.id.business_soln);
services = (Button) findViewById(R.id.services);
office = (Button) findViewById(R.id.office_automation);
inquire = (Button) findViewById(R.id.inquire);
connect = (Button) findViewById(R.id.connect);
}
@Override
public void onClick(View v) {
switch (v.getId())
{
case R.id.discover_us:
p = new Intent(this,DiscoverUs.class);
startActivity(p);
break;
case R.id.why_us:
p = new Intent(this,WhyTechbiz.class);
startActivity(p);
break;
case R.id.office_automation:
p = new Intent(this,Office_Automation.class);
startActivity(p);
break;
case R.id.services:
p = new Intent(this,Services.class);
startActivity(p);
break;
case R.id.enterprise_soln:
p = new Intent(this,Enterprise_Soln.class);
startActivity(p);
break;
case R.id.business_soln:
p = new Intent(this,Business_Soln.class);
startActivity(p);
break;
case R.id.inquire:
p = new Intent(this,Inquire.class);
startActivity(p);
break;
case R.id.connect:
p = new Intent(this,Connect.class);
startActivity(p);
break;
}
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}
@Override
public void onBackPressed() {
if (back_pressed_time + PERIOD > System.currentTimeMillis()) {
super.onBackPressed();
} else {
back_pressed_time = System.currentTimeMillis();
Toast.makeText(MainActivity.this, "Press once again to exit!", Toast.LENGTH_SHORT).show();
}
}
Я не думаю, что этого фрагмента кода достаточно, чтобы отследить вашу проблему. Есть ли что-то еще в вашей «Активности», когда вы нажимаете кнопку «Назад»? –
Пожалуйста, определите _ «choppy exit» _. –
Choppy означает, что он замораживает среднюю закрытие приложения, показывая недавний список приложений, а затем, в конце концов, покидает – HM88