当我们重新启动应用程序崩溃后,由于FindViewById
返回null,应用程序在此活动中崩溃,直到我们必须卸载该应用程序
我有这段代码:
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();
}
}