两个活动在第二次进行相同的转换

时间:2015-03-21 23:05:16

标签: java android android-intent

我对透明活动的过渡存在严重问题。在模拟器中首次安装并启动应用程序时,透明活动可以很好地完成转换。但是,当我从应用程序中退出并返回时,两个活动都会进行相同的转换!

WallpaperAct是活动背景& ConnexionForm是透明的Activity

public class WallpaperAct extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_arriere_plan);
    Intent  i = new Intent(WallpaperAct.this,ConnexionFormulaire.class);
    startActivity(i);
    overridePendingTransition(R.animator.animationbas_haut,0);


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.arriere_plan, menu);
    return true;
}   

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

每次创建活动时都会调用

onCreate,这指的是活动的生命周期,是否刚刚安装了应用程序。请注意Activity的文档:

  

当活动开始时调用。这是大多数初始化应该去的地方:调用setContentView(int)来扩展活动的UI,使用findViewById(int)以编程方式与UI中的小部件交互......

如果您希望确定应用程序是否第一次运行,那么您可以通过设置(布尔)首选项来实现,通过SharedPreferencesfirstRun。对于特定示例,您可以查看SO问题Check if application is on its first run

相关问题