使用活动生命周期处理活动

时间:2014-02-27 12:06:07

标签: android android-lifecycle

在我的应用程序中,我正在 SplashScreenActivity.java 之后启动 LoginActivity.java ,但每当我正确关闭它后再次启动我的应用程序时,不会从完全活动开始 LoginActivity.java (必须是)

我正在玩小案例 - 案例说明:如果 txtEvent并且txtOperative等于null 启动 LicenseListActivity.java else 当前活动(LoginActivity.java)。

但每次调用 LicenseListActivity.java 而我的txtEvent和txtOperative都不为null时,我使用Log进行检查。

where i am doing mistake ? which method i need to use to make my case successfull?

LoginActivity.java:

 private SharedPreferences prefs;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_login);

                txtDeviceID.setText(deviceID);
             txtEmailID.setText(emailID);

             prefs = PreferenceManager
                        .getDefaultSharedPreferences(this);

             txtEvent.setText(prefs.getString("autoSaveEvent", event));
             Log.d("txtEvent::onCreate::", txtEvent.getText().toString());           


             txtOperative.setText(prefs.getString("autoSaveOperative", operative));
             Log.d("txtOperative::onCreate::", txtOperative.getText().toString());  

 txtEvent.addTextChangedListener(new TextWatcher() {
                  @Override
                   public void onTextChanged(CharSequence s, int start, int before,
                                            int count)
                  {

                  }

                  @Override
                    public void beforeTextChanged(CharSequence s, int start, int count,
                                                int after)
                  {

                  }

                  @Override
                    public void afterTextChanged(Editable s)
                  {
                    prefs.edit().putString("autoSaveEvent", s.toString()).commit();
                  }
                });

             txtOperative.addTextChangedListener(new TextWatcher() {
                  @Override
                   public void onTextChanged(CharSequence s, int start, int before,
                                            int count)
                  {

                  }

                  @Override
                    public void beforeTextChanged(CharSequence s, int start, int count,
                                                int after)
                  {

                  }

                  @Override
                    public void afterTextChanged(Editable s)
                  {
                    prefs.edit().putString("autoSaveOperative", s.toString()).commit();
                  }
                });

             strEvent = txtEvent.getText().toString();
             strOperative = txtOperative.getText().toString();

             if  (txtEvent.getText().toString().equals("") && txtOperative.getText().toString().equals(""))
                {
                    Intent intentCall = new Intent(LoginActivity.this, LicenseListActivity.class);
                    startActivity(intentCall);
                }
             else 
                {
                // show current activity
                }


}

    @Override
      protected void onPause() {
        super.onPause();

      }

      @Override
      protected void onResume() {
        super.onResume();

      }

      @Override
      protected void onStop() {
        super.onStop();

      }

      @Override
      protected void onDestroy() {
        super.onDestroy();

      }

      @Override
      protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);

      }

      @Override
      protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);

      }
     }

0 个答案:

没有答案