我正在开发一个应用程序,其中我有一个名为“A”的活动和另一个名为“B”的活动。我曾意图在“A”到“B”之间导航,但当我的应用程序进入后台时Intent
仍然有效。
当应用程序进入暂停状态时,我想要停止从“A”导航到“B”。我该怎么做?
这是代码:
public class CSplashScreen extends AppCompatActivity {
// Splash screen timer
private static final int m_n_SplashTimeOut = 4000;
private ImageView splash_image;
private boolean isConnected;
private static CLoginSessionManagement s_oCloginSession;// refernce of loginsession management
public void onAttachedToWindow() {
super.onAttachedToWindow();
Window window = getWindow();
window.setFormat(PixelFormat.RGBA_8888);
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
if (NetworkUtil.isConnected(getApplicationContext())){
}else {
CSnackBar.getInstance().showSnackBarError(findViewById(R.id.mainLayout), "No internet connection available", getApplicationContext());
}
init();//initialize controls
}
private void init() {// initialize controls
Animation animation = null;
splash_image = (ImageView) findViewById(R.id.splash_image);
animation = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.zoom_out);
animation.setDuration(1500);
splash_image.startAnimation(animation);
new Handler().postDelayed(new Runnable() {
// This method will be executed once the timer is over
@Override
public void run() {
Intent i = new Intent(CSplashScreen.this, CMainActivity.class);
startActivity(i);
}
}, m_n_SplashTimeOut);// spalsh screen timing
}
}
答案 0 :(得分:0)
@Override
public void run() {
if (!isFinishing()) {
startActivity(new Intent(CSplashScreen.this, CMainActivity.class));
}
}
答案 1 :(得分:0)
你可以在onPause()中使用' isPauch' ..使其成为真,并在onResume()中将其设为false。并检查flag是否为false然后转到其他活动。