Android FragmentActivity findviewbyid() is null in OnCreate

515 views Asked by At

After the Crash when we relaunch the app the app is getting crash in this Activity because of FindViewById return null until we have to uninstall that app

I have this code:

public class StartupScreenActivity : FragmentActivity
{
    #region Fields

    private Button btnSignIn, btnIamNew;

    private AutoScrollViewPager aScrollViewPager;
    public HomePagerFragmentAdaptor hAdapter;
    public PageIndicator nIndicator;

    #endregion

    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);
        RequestWindowFeature (WindowFeatures.NoTitle);
        SetContentView (Resource.Layout.StartupScreenLayout);

        #region Object initializer

        hAdapter = new HomePagerFragmentAdaptor (SupportFragmentManager);
        aScrollViewPager = FindViewById<AutoScrollViewPager> (Resource.Id.pager);
        nIndicator = FindViewById <CirclePageIndicator> (Resource.Id.indicator);

        btnSignIn = FindViewById<Button> (Resource.Id.SignIn);
        btnIamNew = FindViewById<Button> (Resource.Id.IAmNew);

        #endregion

        #region Apply Font

        btnSignIn.SetTypeface (FontFactory.GetFontFocoRG(this),TypefaceStyle.Normal);
        btnIamNew.SetTypeface (FontFactory.GetFontFocoRG(this),TypefaceStyle.Normal);

        #endregion

        #region Calling Methods

        aScrollViewPager.Adapter = hAdapter;
        aScrollViewPager.startAutoScroll();
        nIndicator.SetViewPager (aScrollViewPager);

        #endregion

        #region Event Handler 

        btnSignIn.Click += SignInOnClick;
        btnIamNew.Click += IamNewOnClick;
        #endregion
    } 

    protected override void OnResume ()
    {
        base.OnResume ();
        aScrollViewPager.startAutoScroll();
    }

    private void IamNewOnClick (object sender, EventArgs e)
    {
        aScrollViewPager.stopAutoScroll();
        this.LaunchActivity (typeof(GetInvitedActivity));
    }

    public void SignInOnClick (object sender, EventArgs e)
    {
        aScrollViewPager.stopAutoScroll();
        (this as Activity).LaunchActivity (typeof(LoginActivity));
    }
    public override void OnBackPressed()
    {
        Intent intent = new Intent(Intent.ActionMain);
        intent.AddCategory(Intent.CategoryHome);
        intent.SetFlags(ActivityFlags.ClearTop);

        StartActivity(intent);
        Finish();
    }
}
0

There are 0 answers