如何定位的变化和离开应用程序的Andr​​oid区分 [英] How to distinguish between orientation change and leaving application android

查看:64
本文介绍了如何定位的变化和离开应用程序的Andr​​oid区分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,如果调用随后的onCreate的屏幕变化的方向,目前活动的onDestroy()(),以有效地重新创建活动。 我需要知道如何以编程方式告诉我们,如果应用程序正在退出或者只是方向正在发生变化。

I understand that when the orientation of the screen changes, the current activities onDestroy() is called followed by the onCreate() to effectively recreate the activity. I need to know how to programmatically tell if the application is being exited or if just the orientation is being changed.

一个方法是为previous活动通知我,当它的onR​​esume()方法被调用,这将让我知道,用户拥有pressed后退按钮和方向一直没有改变

One method is for the previous activity to notify me when its onResume() method is being called, this will let me know that the user has pressed the back button and the orientation hasn't been changed.

P.S。我正在寻找一个解决方案,比听一回硬件按钮,点击更优雅。

P.S. I'm looking for a solution more elegant than listening for a back hardware button click.

下面是我想做的事:

我有两个标签,当活动被首次输入或用户已离开活动和正在进入它,有一定的标签基于某些准则被显示。

I have two tabs, when the activity is being entered for the first time or the user has left the activity and is now entering it, a certain tab is displayed based on some criterion.

在方向改变,我需要留在同一选项卡上。

When the orientation changes, i need to stay on the same tab.

推荐答案

使用活动的 isFinishing()方法。

@Override
  protected void onDestroy() {
    super.onDestroy();
    if (isFinishing()) {
      // do stuff
    } else { 
      //It's an orientation change.
    }
  }

这篇关于如何定位的变化和离开应用程序的Andr​​oid区分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆