Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Activity(Label = "App",
- Icon = "@drawable/ic_launcher",
- Theme = "@style/splashscreen",
- MainLauncher = true,
- ScreenOrientation = ScreenOrientation.Portrait)]
- public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity
- {
- protected override void OnCreate(Bundle bundle)
- {
- SetTheme(Resource.Style.MainTheme);
- TabLayoutResource = Resource.Layout.Tabbar;
- ToolbarResource = Resource.Layout.Toolbar;
- base.OnCreate(bundle);
- Forms.Init(this, bundle);
- LoadApplication(new App());
- StartBackgroundService();
- IsAppRunning = true;
- }
- private void StartBackgroundService() {
- StopService = false;
- RealtimeService.StopServiceEventHandler += StopServiceEventHandler;
- StartService(new Intent(Forms.Context, typeof(BackgroundRealtimeService)));
- }
- private void StopServiceEventHandler(object sender, object o) {
- if (StopService) {
- StopService(new Intent(Forms.Context, typeof(BackgroundRealtimeService)));
- }
- }
- protected override void OnDestroy()
- {
- IsAppRunning = false;
- base.OnDestroy();
- }
- }
- }
- [Service]
- public class BackgroundRealtimeService : Service
- {
- public async void Initialize() {
- // Service Code
- }
- public override void OnCreate() {
- base.OnCreate();
- }
- public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId) {
- new Task(Initialize).Start();
- return StartCommandResult.Sticky;
- }
- public override IBinder OnBind(Intent intent)
- {
- return null;
- }
- }
- }
Add Comment
Please, Sign In to add comment