据我所知,android Activity生命周期表明OnCreate总是先调用。但是当我在Visual Studio 2015中调试我的应用程序时,OnResume中的断点首先命中,然后进入OnCreate。
这让我发疯,这是一个简单的应用程序。我有一个名为StartScreen
的启动器活动,我在调用MainAcivity
中的OnResume
StartScreen.cs“OnResume()”
Task startupWork = new Task(() => {
Log.Debug(General.TAG, "Authenticate");
applicationData = dataProvider.Retreive(General.DATA_PROVIDER_STRING);
Log.Debug(General.TAG, "Got authentication");
});
startupWork.ContinueWith(t => {
if (applicationData != null && applicationData.Any())
{
Log.Debug(General.TAG, "Work is finished - Check connectivity.");
if(General.InternetConnected(this))
StartActivity(new Intent(Application.Context, typeof(MainActivity)));
else
{
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.SetTitle("Network Error");
alert.SetMessage("No network found, please check your internet connection.");
alert.SetPositiveButton("Ok", (senderAlert, args) => {
});
Dialog errorDialog = alert.Create();
errorDialog.Show();
}
}
else
{
Log.Debug(General.TAG, "Work is finished - start LoginActivity.");
StartActivity(new Intent(Application.Context, typeof(LoginActivity)));
}
}, TaskScheduler.FromCurrentSynchronizationContext());
startupWork.Start();
现在我的MainActivity
我现在只有两个空方法
MainActivity.cs
protected override void OnResume()
{
base.OnResume()
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle)
}
我在两种方法中都设置了断点,并且始终首先使用OnResume命中。我不明白为什么。
我做的是什么造成的?