Monodroid Listview - xamarin.android

I have tried making a listview for a android app like this tutorial.
However, when I tried making it, VS2010 started whining about an error, not sure what it means.
I hope someone can help me.
This is the error:
Activity1.OnCreate(Android.OS.Bundle)': cannot change access modifiers
when overriding 'protected' inherited member
'Android.App.Activity.OnCreate(Android.OS.Bundle)'

Based on the error message you need to change:
public override void OnCreate (Bundle bundle)
to
protected override void OnCreate (Bundle bundle)

Related

singleton in framework with error: initializer is inaccessible due to 'private' protection level

So, I made a framework in swift and at first I wanted to use a singleton class. I built it and put the .Framework file into a new project to test it. Than I got this error:
'getInstance' is inaccessible due to 'internal' protection level
. I tried looking for anyone with the same problem, but nothing I found worked. It might be because its a framework. After hours of meaningless searching, I gave up on the singleton and I got almost the same error with a normal class.
'mySDK' initializer is inaccessible due to 'private' protection level
I tried making the class public, the initializer public, but nothing seems to change. Anyone experienced any problem like this? I never worked on frameworks before, so maybe its the obj-c header that have to be modified. If you need any more information, please just ask.
Thank you all, in advance.
Edit:
This is the getInstance func. I wrote it only, because the mySDK.myInstance seemed to give the same error.
static let myInstance = mySDK()
public static func getInstance() -> mySDK {
return myInstance
}
I don't know what caused the error, but I managed to fix it by creating a new project, than copy pasting the code from the old to the new.
I found the source of the problem. If I turned off the build active architecture only option in the build settings of the framework, It gave me this error.
You can create a singleton class in a framework like this. Please make the public Class and public static getInstance function.
public class ClassName {
// Singleton instance
private static var instance : ClassName?
/********************* Singleton Instance ************************************/
public static func getInstance() -> ClassName {
if (instance != nil) {
return instance!
}
// Initialize instance.
instance = ClassName()
return instance!
}
}

What is the best way to implement firebase crash report in iOS swift 3

Here incase of android firebase crash can be implemented in APPLICATION class like.. below example
(...here, if android app is crashed this overrriden method uncaughtException(Thread thread, Throwable e) is called where we report crash to firebase...)
So, I want to know if there is any better way to implement firebase crash in iOS swift 3 like this.
/** onCreate method of MainApplication.java */
#Override
public void onCreate() {
super.onCreate();
reportFirebaseCrash();
}
/** Report FirebaseCrash Exception if application crashed */
private void reportFirebaseCrash() {
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
#Override
public void uncaughtException(Thread thread, Throwable e) {
AppUtils.showLog(TAG, "reportFirebaseCrash");
FirebaseCrash.report(e);
}
});
}
Highly recommend you check out the Firebase docs — they're quite well done and should give you all the help you need to get started.
In particular, the simplest way to get up and running is to use the crash reporting pod:
pod 'Firebase/Crash'
Then you need to configure a FIRApp shared instance. Once that's set up (or if you have already), you need to configure your build system to upload crash reports. The docs link includes all the necessary details to do it, but tl;dr, you need to create a new Run Script build phase:
# Replace this with the GOOGLE_APP_ID from your GoogleService-Info.plist file
GOOGLE_APP_ID=1:my:app:id
# Replace the /Path/To/ServiceAccount.json with the path to the key you just downloaded
"${PODS_ROOT}"/FirebaseCrash/upload-sym "/Path/To/ServiceAccount.json"
Firebase also supports Bitcode in order to gather crash data from production users.

The Type initializer for 'Realms.Realm' threw an exception

I am trying to implement Realm on a smaller Xamarin/Mvvmcross/iOS/Droid project in order to test it's ability to replace SQLite.
I have it working well on the iOS project but am getting exceptions on the Droid project when attempting to call Realm.GetInstance();
The Type initializer for 'Realms.Realm' threw an exception
Inner Exception
System.Reflection.ReflectionTypeLoadException
The classes in the module cannot be loaded.
I have narrowed it what I believe is an issue with reflection if the MvvmCross setup occurs before the Realm dll is loaded.
For example if I call Realm.GetInstance() in any activity that inherits from MvxActivity or MvxAppCompatActivity (or anywhere in the Mvvmcross Setup / CreateApp process) the exception occurs.
If however I call var db = Realm.GetInstance() (& db.Close()) from a normal Droid Activity first, and then start the Mvx Setup process, by starting an MvxActivity, from the Droid Activity it works fine, and continues to work through the application lifecycle.
Likewise if I subclass Application and open a Realm instance in OnCreate() and close it Real will initialise anywhere else in the application.
sample code
//works
[Application]
public class CustomApplication : Application
{
public CustomApplication (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer)
{
}
public override void OnCreate ()
{
base.OnCreate ();
var db = Realm.GetInstance ();
db.Close ();
}
}
//does not work unless Realm.GetInstance() has already been called once
[Activity(Label = "View for FirstViewModel")]
public class FirstView : MvxActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.FirstView);
var db = Realm.GetInstance ();
db.Close ();
}
}
I've put a test project on github at https://github.com/vurtigo/TestRealm
This is an unfortunate mix-up between Realm and Xamarin Android.
The static constructor on the Realm class walks through all the assemblies in the current AppDomain to discover all the types that inherit from RealmObject. However, if at the time Xamarin Android builds Java binding code this will define a new System.Reflection.Emit.AssemblyBuilder assembly that will raise a TypeLoadException when its types are enumerated (see Bug 39679 - ReflectionTypeLoadException after some reflection stuff).
The workaround is to cause the Realm static constructor to be invoked before any of the MvvmCross code causes Xamarin Android to emit binding code. You can do that by accessing any of the static members on Realm such as ReferenceEquals or even by including it in a typeof(Realm) expression. I suppose MvxApplication.Initialize() is a good place to do it.
In any case, I have proposed a fix that will ignore AssemblyBuilder instances in general. The very next Realm release should include it and you'll be able to delete the workaround code as soon as you upgrade.

TinyIoC, Xamarin.iOS, linker settings

I'm trying to get TinyIoC working on Xamarin.iOS, but I'm not having a lot of luck. My project linker settings are set to "Link SDK assemblies only".
I'm literally doing something this simple:
public interface IPerson { int age { get; } }
public class Person : IPerson { public int age { get { return 99; } } }
Then my registration code looks like this (I've just placed it in my AppDelegate in a toy app):
TinyIoCContainer.Current.Register<IPerson,Person>.AsMultiInstance();
When I attempt to grab an IPerson, I get a runtime exception saying that IPerson cannot be resolved (this code is found immediately after the registration code in the AppDelegate of the toy app):
IPerson person = TinyIoCContainer.Current.Resolve<IPerson>();
Here's the error:
Unable to resolve type: TinyTest.IPerson
If, however, I change the linker settings to "Don't link", everything works fine. This is obviously untenable, though, because the binary becomes enormous.
I've tried placing [Preserve] attributes on the IPerson interface and the Person class, but no dice. I also tried just manually declaring a variable of type IPerson and instantiating it with a new Person() and then grabbing the age property, just to make sure the type was included in the build, but no luck there either.
Feel like I'm missing something here - can someone point me in the right direction?
Thank you!
This is a bug because reflection is used to call an internal Expression<TDelegate> constructor.
The linker cannot analyze reflection usage (it's beyond static analysis) so it must be aware of those special cases.
This is obviously untenable, though, because the binary becomes enormous.
Keep using the default Link SDK option but add the --linkskip=System.Core to your Additional mtouch arguments, inside your Project Options, iOS Build.
That way only System.Core (from the SDK) will not be linked and the increase in size will be much smaller. Of course this is only a workaround until a new version fix the issue properly.

setExtent causes ScrollView not found error in BlackBerry 9000

This--
import net.rim.device.api.ui.container.VerticalFieldManager;
public class FixedHeightVerticalFieldManager extends VerticalFieldManager
{
private int height;
public FixedHeightVerticalFieldManager(int height)
{
super();
this.height = height;
}
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(maxWidth, height);
setExtent(height);
}
}
--causes the emulator to hang with the runtime exception net.rim.device.api.ui.ScrollView not found. It seems to be caused by the call to setExtent, which is a method VerticalFieldManager inherited from Field, which is in the 4.6 API that the emulator is set up to use. Why? What does ScrollView have to do with anything?
net.rim.device.api.ui.ScrollView is not available in 4.6 API - that's the reason. So I suspect you're using the ScrollView somewhere in your code while you are trying to run on a 4.6 OS simulator.
Also what API version is used to build the project? Normally (if you'd use 4.6 API lib/JDE) you should have got this error at building step (versus in runtime).
UPDATE:
I really have no idea why this is related to setExtent().
I suspect most likely you compile using API 6. For API 6 the inheritance chain looks as Field > ScrollView > Manager > VerticalFieldManager, so when you compile a VerticalFieldManager it may use ScrollView. Maybe that's why you get the error on API 4.6 simulator. You can test this idea by trying to run your app on any OS 6.0 simulator. I believe it should not give this error.
P.S. I have not used BB Eclipse plugin much (once I tried, but then refused because of some issues), so I can't say where exactly to check the API version. However surely there must be a way to check that.

Resources