我正在开发一个Xamarin Android项目。我在Splash(第一个)屏幕上有一些动画。结束所有动画后,我正在开始一项活动。所以问题是第一次导航下一个Activity需要2-3秒。之后,除非我清除最近的应用程序列表,否则只需一秒钟即可在该Activity上导航。再次清理后需要2-3秒。
请在此处说明错误以及如何修复。
启动活动
[Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true,NoHistory = true, ScreenOrientation = ScreenOrientation.Portrait)]
public class SplashScreenActivity : Activity
{
private ImageView CircleImage;
private ImageView SquakrLogo;
private TextView text;
private RelativeLayout logoRelativeLayout;
Animation CircleImageAnimation;
Animation SquakrLogoAnimation;
Animation LargeDotAnimation;
Animation PluseAnimation;
Intent intentObject;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.SplashScreen);
logoRelativeLayout = FindViewById<RelativeLayout>(Resource.Id.logo_layout);
CircleImage = FindViewById<ImageView>(Resource.Id.circle_image_view);
SquakrLogo = FindViewById<ImageView>(Resource.Id.logo_image_view);
text = FindViewById<TextView>(Resource.Id.text);
CircleImageAnimation = AnimationUtils.LoadAnimation(this, Resource.Animation.SplashTVAnimation);
SquakrLogoAnimation = AnimationUtils.LoadAnimation(this, Resource.Animation.SplashLogoAnimation);
LargeDotAnimation = AnimationUtils.LoadAnimation(this, Resource.Animation.SplashLastAnimation);
PluseAnimation = AnimationUtils.LoadAnimation(this, Resource.Animation.SplashPulseAnimation);
intentObject = new Intent(this, typeof(MainActivity));
}
public override void OnWindowFocusChanged(bool hasFocus)
{
base.OnWindowFocusChanged(hasFocus);
if(hasFocus)
{
CircleImage.StartAnimation(CircleImageAnimation);
CircleImageAnimation.AnimationEnd += CircleImageAnimation_AnimationEnd;
}
}
private void CircleImageAnimation_AnimationEnd(object sender, Animation.AnimationEndEventArgs e)
{
SquakrLogo.StartAnimation(SquakrLogoAnimation);
CircleImage.Visibility = ViewStates.Invisible;
logoRelativeLayout.Visibility = ViewStates.Visible;
SquakrLogoAnimation.AnimationStart += SquakrPluseAnimation_AnimationStart;
SquakrLogoAnimation.AnimationEnd += SquakrPluseAnimation_AnimationEnd;
}
private void SquakrPluseAnimation_AnimationStart(object sender, Animation.AnimationStartEventArgs e)
{
global::Android.Widget.RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(50, 50);
param.AddRule(LayoutRules.CenterInParent);
CircleImage.LayoutParameters = param;
CircleImage.Visibility = ViewStates.Visible;
}
private void SquakrPluseAnimation_AnimationEnd(object sender, Animation.AnimationEndEventArgs e)
{
CircleImage.StartAnimation(PluseAnimation);
PluseAnimation.AnimationEnd += SquakrLogoAnimation_AnimationEnd;
}
private void SquakrLogoAnimation_AnimationEnd(object sender, Animation.AnimationEndEventArgs e)
{
RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MatchParent, RelativeLayout.LayoutParams.MatchParent);
param.AddRule(LayoutRules.CenterInParent);
CircleImage.LayoutParameters = param;
CircleImage.ScaleX = 2.0f;
CircleImage.ScaleY = 2.0f;
CircleImage.StartAnimation(LargeDotAnimation);
LargeDotAnimation.AnimationStart += delegate
{
logoRelativeLayout.Visibility = ViewStates.Invisible;
};
LargeDotAnimation.AnimationEnd += Last_AnimationEnd;
}
private void Last_AnimationEnd(object sender, Animation.AnimationEndEventArgs e)
{
StartActivity(intentObject);
Finish();
}
}
主要活动
#region Methods
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
initTodaysLineUp();
GetSavedToken();
if (!string.IsNullOrEmpty(accessToken) && !string.IsNullOrEmpty(refreshToken))
{
GetUserPreferences();
}
//PackageInfo info = this.PackageManager.GetPackageInfo("co.Squawkr", PackageInfoFlags.Signatures);
//foreach (Android.Content.PM.Signature signature in info.Signatures)
//{
// MessageDigest md = MessageDigest.GetInstance("SHA");
// md.Update(signature.ToByteArray());
// string keyhash = Convert.ToBase64String(md.Digest());
//}
if(SquawkrLoginManager.getInstance().isLoggedIn()){
UserInfo userInfo = SquawkrLoginManager.getInstance().GetLastLoggedInUser();
UpdatePushBadgeCount(userInfo);
if (!string.IsNullOrEmpty(SquawkrLoginManager.getInstance().getDeviceId()) && !SquawkrLoginManager.getInstance().sendDeviceIdToServer())
{
SquawkrLoginManager.getInstance().SendNotificationRegistrationToServer(this);
}
}
}