I'm not usually posting questions on forums like this one, but today my frustration reached the sky.
I am trying to implement a solution that would let me update the Exchange rate list in my application every every hour/day (doesn't matter). I was looking for the answer to my problem on many forums, but even though other people had the same problem of onReceive not being called, none of answers helped me.
I am currently trying to run a Broadcast Receiver that is being fired by AlarmManager's SetRepeating Method. My code for Main activity + Receiver + Manifest look like this:
Main method (just a block of code with starting the alarm):
var lvarManager = (AlarmManager)GetSystemService (Context.AlarmService);
Intent lvarCurrencyIntent = new Intent (this, typeof(CurrencyUpdateService));
var lvarPendingIntent = PendingIntent.GetBroadcast (this, 0, lvarCurrencyIntent, PendingIntentFlags.CancelCurrent);
lvarManager.SetRepeating (AlarmType.Rtc, 1000, 5000, lvarPendingIntent);
Receiver:
public class CurrencyUpdateService : BroadcastReceiver
{
public override void OnReceive (Context context, Intent intent)
{
Toast.MakeText (context, "Running", ToastLength.Short).Show ();
}
}
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="SplitTheBill.SplitTheBill" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="16" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application android:label="SplitTheBill" android:icon="@drawable/groups"></application>
<receiver android:process=":remote" android:name=".CurrencyUpdateService"/>
<provider android:name="mono.MonoRuntimeProvider" android:exported="false" android:initOrder="2147483647" android:authorities="StockService.StockService.mono.MonoRuntimeProvider.__mono_init__" />
I want to state that I'm a somewhat new user of Xamarin and as it quite succesfully makes shure that you don't touch Manifest files, I only added the line:
<receiver android:process=":remote" android:name=".CurrencyUpdateService"/>
I tried running the code in a fresh solution and it didn't work. I tried using different types of Alarm types and Services with no luck.
Feel free to suggest your own solutions and laugh at my face for asking obvious questions ;)