Guest User

Untitled

a guest
Dec 11th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. [Activity(Label = "App",
  2. Icon = "@drawable/ic_launcher",
  3. Theme = "@style/splashscreen",
  4. MainLauncher = true,
  5. ScreenOrientation = ScreenOrientation.Portrait)]
  6. public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity
  7. {
  8.  
  9. protected override void OnCreate(Bundle bundle)
  10. {
  11.  
  12. SetTheme(Resource.Style.MainTheme);
  13.  
  14. TabLayoutResource = Resource.Layout.Tabbar;
  15. ToolbarResource = Resource.Layout.Toolbar;
  16. base.OnCreate(bundle);
  17.  
  18. Forms.Init(this, bundle);
  19.  
  20. LoadApplication(new App());
  21. StartBackgroundService();
  22. IsAppRunning = true;
  23. }
  24.  
  25. private void StartBackgroundService() {
  26. StopService = false;
  27. RealtimeService.StopServiceEventHandler += StopServiceEventHandler;
  28. StartService(new Intent(Forms.Context, typeof(BackgroundRealtimeService)));
  29. }
  30.  
  31. private void StopServiceEventHandler(object sender, object o) {
  32. if (StopService) {
  33. StopService(new Intent(Forms.Context, typeof(BackgroundRealtimeService)));
  34. }
  35. }
  36.  
  37.  
  38. protected override void OnDestroy()
  39. {
  40. IsAppRunning = false;
  41. base.OnDestroy();
  42. }
  43. }
  44. }
  45.  
  46. [Service]
  47. public class BackgroundRealtimeService : Service
  48. {
  49. public async void Initialize() {
  50.  
  51. // Service Code
  52.  
  53. }
  54.  
  55.  
  56. public override void OnCreate() {
  57. base.OnCreate();
  58. }
  59.  
  60. public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId) {
  61.  
  62. new Task(Initialize).Start();
  63. return StartCommandResult.Sticky;
  64. }
  65.  
  66.  
  67. public override IBinder OnBind(Intent intent)
  68. {
  69. return null;
  70. }
  71. }
  72. }
Add Comment
Please, Sign In to add comment