I’ve got a small problem (and it’s probably seriously nothing).
I have a small app which starts like this
namespace Paul.App
{
[Activity(Label = "@string/ApplicationName", MainLauncher = true, Theme = "@android:style/Theme.NoTitleBar",
ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait, Icon = "@drawable/icon")]
public class Paul : Application
{
public static Paul Application;
public Paul(IntPtr handle, JniHandleOwnership transfer) : base(handle, transfer)
{
In this app, I have
public Database dbm;
Database is a class which does SQL things
In this namespace, I also have an OnCreate which calls a new activity which starts like this
namespace Paul.App.Splash
{
[Activity(Theme = "@style/Theme.Splash", MainLauncher = true, NoHistory = true)]
public class Splash : Activity
{
protected override void OnCreate(Bundle bundle)
{
This is fine and everything is ok. Except for one thing. I can’t instantate the database!
If I put into the OnCreate or the the Paul(IntPtr…) and use in other activities
dbm = new DBManager();
the splash starts, but if I try and access dbm using ((Paul)Application).dbm it returns null.
If I do this in the Splash activity
((Paul)Application).dbm = new DBManager();
if (((Paul)Application).dbm.SetupDB() != false)
{
Toast.MakeText(this, "Database failed to initialise", ToastLength.Long);
return;
}
the debugger tells me that ((Paul) is unknown.
It should be a simple thing to do – I’m trying to instantate SQLite once and then use it throughout the app.
Any help here would be appreciated.
Paul
In quickly looking through your code I see that you’re decorating your Application class with the [Activity] attribute, which is incorrect. Instead what you want to do is use
ApplicationAttribute, which will result in the proper AndroidManifest.xml output. Try changing it to look like this: