Hello vanKraster-4073,
Welcome to our Microsoft Q&A platform!
it gives me an error something like that : Unable to find explicit activity class {MainActivity} have you declared this activity in your AndroidManifest.xml
This is because the MainActivity class has been disabled and it's not eabled before calling StartActivity
command. It requires to specify the MainActivity Class as the parameter explicitly.
Here is the sample code, you could refer to it.
[BroadcastReceiver]
public class TestReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
PackageManager p = Android.App.Application.Context.PackageManager;// this.PackageManager;
ComponentName componentName = new ComponentName(context, MainActivity.Instance.Class);
p.SetComponentEnabledSetting(componentName, ComponentEnabledState.Enabled, ComponentEnableOption.DontKillApp);
Intent i = new Intent(context, typeof(MainActivity));
i.SetFlags(ActivityFlags.NewTask);
context.StartActivity(i);
}
}
public class MainActivity : AppCompatActivity
{
public static MainActivity Instance { get; set; }
protected override void OnCreate(Bundle savedInstanceState)
{
...
Instance = this;
}
}
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.