0
votes

I have a service which handles my push notification. When the app is running, everything is fine, but once the app is not running I am getting a null reference exception. I have traced it back to the following line :

newIntent = Mvx.Resolve<IMvxAndroidViewModelRequestTranslator> ().GetIntentFor (request);

This line is used to get the intent for the status bar notification so when the user clicked on it it will take him to the appropriate page inside the app. I am pretty sure that This is null because the application is not running and the MvvmCross framework did not have a chance to initialize and register the IMvxAndroidViewModelRequestTranslator.

My question is what should I use as an alternative?

UPDATE So I dis some reading and I believe that a regular intent wont work and break my app. I was thinking about creating a dummy activity In my app which will get the regular intent I will send and move on to use the IMvxAndroidViewModelRequestTranslator (which should be not null since the app was started) and create an MvvmCross navigation request.

Any thoughts?

UPDATE 2 Tried the approach above with no luck... still failing on the same line...

So basically the question is how can I launch the app from the status bar while making the MvvmCross eco system start as well...

Thanks

Amit

2
You are correct. You need to create a specific intent, and it is probably that causing the issue. How are you creating your intent? - Ross Dargan
@RossDargan the intent solution wont work. as it will not make the MvvmCross framework initialize and break my app. - Amit Raz

2 Answers

0
votes

So what I ended up doing is once the notification arrived and the Mvx.Resolve threw an exception I (meaning the app is not running), I saved the notification data to the app preferences and launched the app to its main activity and there I simpley checked for the notification data and if it existed I navigated to the appropriate activity.

0
votes

When the Android UI starts, then MvvmCross runs Setup to initialise things like IoC, your application, etc

If you need to initialise your MvvmCross application within a non-UI setting, then try the answer from MvvmCross DataService in an Android Broadcast listener which shows how to access the same setup that the UI uses.