Reputation: 893
I am migrating an app from Xamarin.Android to MAUI. I am getting errors in all of the lifecycle methods. For example:
Error CS0115 'BaseActivity.OnPause()': no suitable method found to override AndroidAppCore (net8.0-android)
In Xamarin.Android I did not get any of these errors in BaseActivity.cs, but I do in MAUI The lifecycle methods work in my LoginActivity in MAUI
Activities/Base/BaseActivity.cs:
namespace Common
{
public abstract class BaseActivity : ISessionExpired, IPBottomNavBarIcon
Activities/Login/LoginActivity.cs:
namespace PApp
{
[Activity]
public class PatientLoginActivity : Common.BaseActivity
Question: What am I missing in BaseActivity ?
Upvotes: 0
Views: 575
Reputation: 13919
From document App lifecycle,we could know:
.NET Multi-platform App UI (.NET MAUI) apps generally have four execution states:
not running
,running
,deactivated
, andstopped
. .NET MAUI raises cross-platform lifecycle events on theWindow
class when an app transitions from the not running state to the running state, the running state to the deactivated state, the deactivated state to the stopped state, the stopped state to the running state, and the stopped state to the not running state.
And the Window
class defines the following cross-platform lifecycle events: Created
,Activated
, Deactivated
,Stopped
,Resumed
,Destroying
.
These cross-platform events map to different platform events, and the following table shows this mapping:
So, you don't need to redefine the lifecycle at all, and you can use these events as needed.
Upvotes: 1
Reputation: 804
Your BaseActivity doesn't inherit from any standard Android activity, hence the error.
e.g. should be
using AndroidX.AppCompat.App;
[Activity(Label = "BaseActivity")]
public class BaseActivity : AppCompatActivity {
}
Upvotes: 0