activity did not call through super.onresume exception - xamarin

In my xamarin forms app, there is crash which is as follows from App Center crashlytics:
android.app.Activity.performResume:
Activity.java - line 7138
android.util.SuperNotCalledException: Activity
{com.tcrsoftware.androidx/md54f7a5b50cfc6839da41f22f8e0e378f9.MainActivity}
did not call through to super.onResume()
android.app.Activity.performResume Activity.java:7138
android.app.ActivityThread.performResumeActivity ActivityThread.java:3850
android.app.ActivityThread.handleResumeActivity ActivityThread.java:3914
android.app.ActivityThread$H.handleMessage ActivityThread.java:1709
android.os.Handler.dispatchMessage Handler.java:102
android.os.Looper.loop Looper.java:154
android.app.ActivityThread.main ActivityThread.java:6823
java.lang.reflect.Method.invoke Method.java
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
ZygoteInit.java:1557
com.android.internal.os.ZygoteInit.main ZygoteInit.java:1445
I just use onResume() in my Shared Library project like:
public partial class App : Application
{
protected override void OnResume()
{
Utility.LogMessage("OnResume: ", LogMessageType.info);
}
}
I did not implement/use onResume() in the MainActivity class of android project.
Where and why this crash occured? And also would it be cause app to crash continously when user tries to open the app?
any updates?

Related

Resolution failed exception in Xamarin IOS prism

I have an iOS application written in Xamarin and I am getting a Unity Exceptions Resolution Failed exception when I try and run the application in iOS. However this error does not happen when I run the android version of the application. The exception is being thrown while the initalize function from prism is taking place.
Here is a snippet from my app.xaml.cs
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
this.RegisterLocal(containerRegistry);
this.RegisterServices(containerRegistry);
this.RegisterPagesForNavigation(containerRegistry);
}
This code all executes and passes.
This is the iOS initialization
Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
PullToRefreshLayoutRenderer.Init();
LoadApplication(new App(new IosInitializer()));
return base.FinishedLaunching(app, options);
}
public class IosInitializer : IPlatformInitializer
{
public void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.Register<IUAirshipUpdate, UAirshipUpdate>();
}
}
This code also executes
The exception being thrown is an argument null exception indicating that IModuleCatelog is not present. I do not understand why it is looking for that module and can not find it. The source code on GitHub indicates that class was registered.
This issue was caused because linker behavior for IOS application was set to full and that causes issues with Unity IOC Container.

Xamarin.Android Architecture Components: Not getting callbacks for lifecycle events

I'm trying to use the architecture components package for detecting when the application enters background or foreground state. The problem is that the callbacks are not being invoked. In the sample code below, the methods onApplicationForegrounded and onApplicationBackgrounded are not invoked:
namespace POC.Droid
{
[Application]
public class MyApp : Application, ILifecycleObserver
{
static readonly string TAG = "MyApp";
public MyApp(IntPtr handle, Android.Runtime.JniHandleOwnership ownerShip) : base(handle, ownerShip)
{
}
public override void OnCreate()
{
base.OnCreate();
ProcessLifecycleOwner.Get().Lifecycle.AddObserver(this);
}
[Lifecycle.Event.OnStop]
public void onAppBackgrounded()
{
Log.Debug(TAG, "App entered background state.");
}
[Lifecycle.Event.OnStart]
public void onAppForegrounded()
{
Log.Debug(TAG, "App entered foreground state.");
}
}
}
My Xamarin version is 8.2.0.16 (Visual Studio Community) and Xamarin.Android.Arch.Lifecycle.Extensions version is 1.0.0. I'm using a Nougat device (7.0) for testing.
TL;DR Please annotate your lifecycle callbacks with [Export]
Here a more detailed description:
Generally, to get the methods of a lifecycle observer be invoked, please make sure that the related packages are present. Here is a part of my packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Xamarin.Android.Arch.Core.Common" version="26.1.0" targetFramework="monoandroid81" />
<package id="Xamarin.Android.Arch.Core.Runtime" version="1.0.0.1" targetFramework="monoandroid81" />
<package id="Xamarin.Android.Arch.Lifecycle.Common" version="26.1.0" targetFramework="monoandroid81" />
<package id="Xamarin.Android.Arch.Lifecycle.Extensions" version="1.0.0.1" targetFramework="monoandroid81" />
<package id="Xamarin.Android.Arch.Lifecycle.Runtime" version="1.0.3.1" targetFramework="monoandroid81" />
This is how this looks in Visual Studio:
To be able to set a lifecycle observer, we need a lifecycle owner. On the application level this can be ProcessLifecycleOwner, just like the original poster showed.
Here is a slightly modified version:
using System;
using Android.App;
using Android.Arch.Lifecycle;
using Android.Util;
using Java.Interop;
namespace Stopwatch_AAC
{
[Application]
public class MyApp : Application, ILifecycleObserver
{
const string TAG = "MyApp";
public MyApp(IntPtr handle, Android.Runtime.JniHandleOwnership ownerShip) : base(handle, ownerShip)
{
}
public override void OnCreate()
{
base.OnCreate();
ProcessLifecycleOwner.Get().Lifecycle.AddObserver(this);
}
[Lifecycle.Event.OnStop]
[Export]
public void Stopped()
{
Log.Debug(TAG, "App entered background state.");
}
[Lifecycle.Event.OnStart]
[Export]
public void Started()
{
Log.Debug(TAG, "App entered foreground state.");
}
}
}
As you can see, you annotate your lifecycle methods with for example [Lifecycle.Event.OnStop]. Also, please note that you need to use [Export]. Please make sure that Mono.Android.Export is referenced in your project as shown in the following screenshot.
If you want to have lifecycle observers for an activity, I suggest to extend AppCompatActivity as it is a lifecycle owner:
using Android.App;
using Android.Arch.Lifecycle;
using Android.OS;
using Android.Support.V7.App;
using Android.Util;
using Java.Interop;
namespace Stopwatch_AAC
{
[Activity(Label = "Minimal", Exported = true, MainLauncher = true)]
public class Minimal : AppCompatActivity, ILifecycleObserver
{
const string TAG = "Stopwatch_AAC";
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Lifecycle.AddObserver(this);
Log.Debug(TAG, Lifecycle.CurrentState.ToString());
}
[Lifecycle.Event.OnAny]
[Export]
public void Hello()
{
Log.Debug(TAG, Lifecycle.CurrentState.ToString());
}
}
}
if you need it in the activities here the events:
protected override void OnStart(){
base.OnStart();
Log.Debug(logTag, "MainActivity.OnStart() called, the activitiy is active");
}
protected override void OnPause()
{
base.OnPause();
Log.Debug(logTag, "MainActivity.OnPause() called, the activity in background");
}
protected override void OnStop()
{
base.OnStop();
Log.Debug(logTag, "MainActivity.OnStop() called, the activity is in background because of other activiy or app");
}
protected override void OnResume()
{
base.OnResume();
Log.Debug(logTag, "MainActivity.OnResume() called, the activity stated");
}
protected override void OnRestart()
{
base.OnRestart();
Log.Debug(logTag, "MainActivity.OnRestart() called, the activity is startet");
}
protected override void OnDestroy()
{
base.OnDestroy();
Log.Debug(logTag, "MainActivity.OnDestroy() called, activity is destroyed");
}
for Xamarin Forms you will find in app.xaml.cs the event which are needed for the apps.
protected override void OnStart ( ) {
// Handle when your app starts
}
protected override void OnSleep ( ) {
// Handle when your app sleeps
}
protected override void OnResume ( ) {
// Handle when your app resumes
}
I have used that package in the past, however I much prefer the implementation by James Montemagno which can be found as a nuget package called "Plugin.CurrentActivity". It creates an application class and implements the ILifecycle events for you.
From the description:
Provides a simple solution for getting access to the current Activity of the application when developing a Plugin for Xamarin.
This will lay down a base "application" class for developers in their Android application with boilerplate code to get them started.
Can be used with Android API 14+
* I am making the assumption that you're not using Xamarin.Forms. This works perfectly for a native Xamarin Android project.
Link to the Github page

displaying dialog during module restore causes java.lang.IllegalStateException: no splash screen available

I have application built on top of Netbeans Platform and I need to do some checks during loading of one of the modules and display a dialog if some of the check fails to let the user to decide what should happen.
Insipired by this tutorial https://platform.netbeans.org/tutorials/60/nbm-login.html I created installer for the module and put the checks and dialog display to the installers method restore().
public class Installer extends ModuleInstall {
#Override
public void restored() {
if (check()) {
DialogDisplayer.getDefault().notify(myDialogDescriptor);
//...
}
}
This works but causes the splash screen to be closed and later there occurs an exception
java.lang.IllegalStateException: no splash screen available
at java.awt.SplashScreen.checkVisible(SplashScreen.java:197)
at java.awt.SplashScreen.update(SplashScreen.java:324)
at org.netbeans.core.startup.Splash$SplashPainter.repaint(Splash.java:401)
at org.netbeans.core.startup.Splash$SplashPainter$1.run(Splash.java:442)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
What can I do to prevent this exception?
I was able to reproduce this exception in a simple standalone module. This seems to be a known bug in NetBeans. A possible work around is to use WindowManager.invokeWhenUIReady() to delay display of the dialog until the main window opens like in this code example.
public class Installer extends ModuleInstall {
#Override
public void restored() {
WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
#Override
public void run() {
NotifyDescriptor.Confirmation dd = new NotifyDescriptor.Confirmation("Do you want to proceed?");
Object result = DialogDisplayer.getDefault().notify(dd);
if (result == DialogDescriptor.OK_OPTION) {
// Do something
}
}
});
}
But this workaround may not be acceptable if your requirement is to display the dialog and take action before the main window opens and is displayed.

requestFeature() must be called before adding content in Xamarin Forms application

I am developing one sample login application using xamarin forms, I developed code in common portable project. When running in Xamarin forms android project, this error is displayed:
Android.Util.AndroidRuntimeException: requestFeature() must be called before adding content
The code is:
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
global::Xamarin.Forms.Forms.Init (this, bundle);
LoadApplication (new App());
}
}
How can I overcome this?
inherit your MainActivity from FormsAppCompatActivity instead of FormsApplicationActivity
https://github.com/xamarin/Xamarin.Forms/issues/13779

Java.Lang.UnsatisfiedLinkError: Native method not found: onResume with Xamarin

This class definition causes an immediate runtime crash on Xamarin for Android.
public class BaseCompatActivity : Android.Support.V7.App.AppCompatActivity
{
protected override void OnResume()
{
base.OnResume();
}
}
The error message is:
Java.Lang.UnsatisfiedLinkError: Native method not found: md5e8727ee9d36911e204981187fd2b13a2.BaseCompatActivity.n_onResume:()V
I have an inheritance chain that goes like this
MainActivity > DrawerActivity > BaseCompatActivity > AppCompatActivity
If I override OnResume in MainActivity or DrawerActivity, there is no problem. It is only if I override it in BaseCompatActivity that I get that error message.
This happens when running API level 17 in the emulator. It does not happen when running on an API level 22 device.
What could be causing this mysterious behaviour?

Resources