[Android] Improve error message when not calling base.OnCreate (#3470)

* Improve error message when forgetting to call base.OnCreate in subclass

* Fixed indent
This commit is contained in:
Morten Nielsen 2018-08-07 14:44:35 -07:00 коммит произвёл Rui Marinho
Родитель 7743b0c945
Коммит 295bd60fb4
1 изменённых файлов: 7 добавлений и 0 удалений

Просмотреть файл

@ -38,6 +38,7 @@ namespace Xamarin.Forms.Platform.Android
AndroidApplicationLifecycleState _previousState;
bool _renderersAdded;
bool _activityCreated;
PowerSaveModeBroadcastReceiver _powerSaveModeBroadcastReceiver;
// Override this if you want to handle the default Android behavior of restoring fragments on an application restart
@ -85,6 +86,11 @@ namespace Xamarin.Forms.Platform.Android
protected void LoadApplication(Application application)
{
if(!_activityCreated)
{
throw new InvalidOperationException("Activity OnCreate was not called prior to loading the application. Did you forget a base.OnCreate call?");
}
if (!_renderersAdded)
{
RegisterHandlerForDefaultRenderer(typeof(NavigationPage), typeof(NavigationPageRenderer), typeof(NavigationRenderer));
@ -142,6 +148,7 @@ namespace Xamarin.Forms.Platform.Android
protected override void OnCreate(Bundle savedInstanceState)
{
_activityCreated = true;
if (!AllowFragmentRestore)
{
// Remove the automatically persisted fragment structure; we don't need them