2016-11-28 5 views
0

メインアクティビティ(AuthenticationActivity)をスキップし、セカンダリアクティビティ(HomeActivity)に着陸すると、アプリが意図したとおりに動作しません。私のコードが正しければ、それはユーザーがログインしている場合はログインしていない場合、またはHomeActivityにAuthenticationActivityを開始し、WelcomeFragment上のユーザーに着陸することになっています。これは、AuthenticationActivityのコードです:。Androidスタジオ:アプリケーションがメインアクティビティをスキップし、起動時にSecondaryActivityに移動する

package com.android.MyApp.main; 

import com.android.MyApp.R; 
import com.android.MyApp.authentication.fragments.WelcomeFragment; 

import android.app.Fragment; 
import android.app.FragmentTransaction; 
import android.content.SharedPreferences; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.content.Intent; 
import android.app.FragmentManager; 

import com.android.MyApp.authentication.Constants; 

public class AuthenticationActivity extends AppCompatActivity{ 



    private SharedPreferences pref; 

    @Override 
    //Applying layout to activity 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_authentication); 
     pref = getPreferences(0); 
     initFragment(); 
     initActivity(); 
    } 

    private void initFragment(){ 
     Fragment mFragment; 
     if(pref.getBoolean(Constants.IS_LOGGED_IN,false)){ 
      initActivity(); 
     }else { 
      mFragment = new WelcomeFragment(); 
      FragmentTransaction ft = getFragmentManager().beginTransaction(); 
      ft.replace(R.id.fragment_frame,mFragment); 
      ft.commit(); 
     } 
    } 


     private void initActivity(){ 
      //Starting HomeActivity from Authentication Activity if user is logged in. 
      Intent intent = new Intent(this, HomeActivity.class); 
      startActivity(intent); 
    } 
} 

私がしてきましたこれにしばらくお待ちいただきました。本当に助けを借りることができました。

答えて

0

これは、認証アクティビティのonCreateメソッドで "initActivity()"メソッドと誤っているためです。

あなたはHomeActivityを開始しました。ユーザがすでにLOGGEDINであるならば、HomeActivityに移動するのonCreate(から呼び出すこの方法を取り外し

private void initActivity(){ 
      //Starting HomeActivity from Authentication Activity if user is logged in. 
      Intent intent = new Intent(this, HomeActivity.class); 
      startActivity(intent); 
    } 

)またはここにいくつかの条件を入れて:

は、あなたのinitActivityコードを参照してください。

+1

ああ、どうして私はそれを拾わなかったのですか、ありがとう!今、アプリを実行すると、空白のページに私の上に着陸している。おそらくXMLファイルでは問題だと思うが、私はそれを理解するだろう。再度、感謝します! – user3519023

+0

あなたのactivity_authentication xmlコードも投稿してください。次に、何が起こっているのか把握することができます。 – Sangeeta

+1

ありがとうございました!私は問題を修正したと思う、私はAuthenticationActivity xmlとその断片のいくつかを変更しなければならなかった。 – user3519023

関連する問題