├── .gitattributes ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── Xamarin.Forms.Background.nuspec ├── build.bat ├── images └── newsfeed.gif ├── scripts └── msbuild.bat └── src ├── SampleBackground ├── SampleBackground.Android │ ├── Assets │ │ └── AboutAssets.txt │ ├── MainActivity.cs │ ├── Properties │ │ ├── AndroidManifest.xml │ │ └── AssemblyInfo.cs │ ├── Resources │ │ ├── AboutResources.txt │ │ ├── Resource.designer.cs │ │ ├── layout │ │ │ ├── Main.axml │ │ │ ├── Tabbar.axml │ │ │ └── Toolbar.axml │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-ldpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ └── values │ │ │ ├── Strings.xml │ │ │ └── styles.xml │ └── SampleBackground.Android.csproj ├── SampleBackground.UWP │ ├── App.xaml │ ├── App.xaml.cs │ ├── Assets │ │ ├── LockScreenLogo.scale-200.png │ │ ├── SplashScreen.scale-200.png │ │ ├── Square150x150Logo.scale-200.png │ │ ├── Square44x44Logo.scale-200.png │ │ ├── Square44x44Logo.targetsize-24_altform-unplated.png │ │ ├── StoreLogo.png │ │ └── Wide310x150Logo.scale-200.png │ ├── MainPage.xaml │ ├── MainPage.xaml.cs │ ├── Package.appxmanifest │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ └── Default.rd.xml │ └── SampleBackground.UWP.csproj ├── SampleBackground.iOS │ ├── AppDelegate.cs │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ ├── Contents.json │ │ │ ├── Icon-App-20x20@1x.png │ │ │ ├── Icon-App-20x20@2x.png │ │ │ ├── Icon-App-20x20@3x.png │ │ │ ├── Icon-App-29x29@1x.png │ │ │ ├── Icon-App-29x29@2x.png │ │ │ ├── Icon-App-29x29@3x.png │ │ │ ├── Icon-App-40x40@1x.png │ │ │ ├── Icon-App-40x40@2x.png │ │ │ ├── Icon-App-40x40@3x.png │ │ │ ├── Icon-App-57x57@1x.png │ │ │ ├── Icon-App-57x57@2x.png │ │ │ ├── Icon-App-60x60@1x.png │ │ │ ├── Icon-App-60x60@2x.png │ │ │ ├── Icon-App-60x60@3x.png │ │ │ ├── Icon-App-72x72@1x.png │ │ │ ├── Icon-App-72x72@2x.png │ │ │ ├── Icon-App-76x76@1x.png │ │ │ ├── Icon-App-76x76@2x.png │ │ │ ├── Icon-App-76x76@3x.png │ │ │ ├── Icon-App-83.5x83.5@2x.png │ │ │ ├── Icon-Small-50x50@1x.png │ │ │ ├── Icon-Small-50x50@2x.png │ │ │ └── ItunesArtwork@2x.png │ │ └── Contents.json │ ├── Entitlements.plist │ ├── Info.plist │ ├── Main.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Resources │ │ ├── Default-568h@2x.png │ │ ├── Default-Portrait.png │ │ ├── Default-Portrait@2x.png │ │ ├── Default.png │ │ ├── Default@2x.png │ │ └── LaunchScreen.storyboard │ ├── SampleBackground.iOS.csproj │ ├── iTunesArtwork@1x.png │ ├── iTunesArtwork@2x.png │ └── iTunesArtwork@3x.png └── SampleBackground │ ├── App.xaml │ ├── App.xaml.cs │ ├── Models │ └── RssData.cs │ ├── SampleBackground.csproj │ ├── Services │ ├── BaseRssFeed.cs │ ├── IRssParserService.cs │ ├── PeriodicBBCNewsRssFeed.cs │ ├── PeriodicCNNRssFeed.cs │ ├── PeriodicWashingtonPostRssFeed.cs │ └── RSSParserService.cs │ ├── ViewModels │ ├── MainPageViewModel.cs │ ├── NewLandingPageViewModel.cs │ └── ViewModelBase.cs │ └── Views │ ├── MainPage.xaml │ ├── MainPage.xaml.cs │ ├── NewLandingPage.xaml │ └── NewLandingPage.xaml.cs ├── Xamarin.Forms.Background.Android ├── ActivityExtension.cs ├── BackgroundService.cs ├── Properties │ └── AssemblyInfo.cs ├── Resources │ └── Resource.Designer.cs └── Xamarin.Forms.Background.Android.csproj ├── Xamarin.Forms.Background.Gtk ├── AppDelegateExtension.cs ├── BackgroundGtkObject.cs ├── Properties │ └── AssemblyInfo.cs └── Xamarin.Forms.Background.Gtk.csproj ├── Xamarin.Forms.Background.Mac ├── AppDelegateExtension.cs ├── Properties │ └── AssemblyInfo.cs └── Xamarin.Forms.Background.Mac.csproj ├── Xamarin.Forms.Background.Tizen ├── ApplicationExtension.cs └── Xamarin.Forms.Background.Tizen.csproj ├── Xamarin.Forms.Background.UWP ├── BackgrounService.cs ├── Properties │ ├── AssemblyInfo.cs │ └── BackgroundService.UWP.rd.xml ├── WindowsPageExtension.cs └── Xamarin.Forms.Background.UWP.csproj ├── Xamarin.Forms.Background.iOS ├── AppDelegateExtension.cs ├── BackgroundService.cs ├── Properties │ └── AssemblyInfo.cs └── Xamarin.Forms.Background.iOS.csproj ├── Xamarin.Forms.Background.sln └── Xamarin.Forms.Background ├── BackgroundAggregatorService.cs ├── BackgroundSharedService.cs ├── IBackgroundTask.cs ├── StartLongRunningTask.cs ├── StopLongRunningTask.cs └── Xamarin.Forms.Background.csproj /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | on: push 3 | 4 | jobs: 5 | build_and_deploy: 6 | runs-on: windows-latest 7 | steps: 8 | - uses: actions/checkout@v1 9 | - name: Build 10 | shell: cmd 11 | run: | 12 | build.bat 13 | - name: Package and upload 14 | run: | 15 | git clone https://github.com/nblockchain/fsx 16 | .\fsx\Tools\fsi.bat fsx\Tools\nugetPush.fsx 0.10 ${{secrets.NUGET_API_KEY}} 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | [Nn]uget/ 25 | 26 | # Visual Studio 2015 cache/options directory 27 | .vs/ 28 | # Uncomment if you have tasks that create the project's static files in wwwroot 29 | #wwwroot/ 30 | 31 | # MSTest test Results 32 | [Tt]est[Rr]esult*/ 33 | [Bb]uild[Ll]og.* 34 | 35 | # NUNIT 36 | *.VisualState.xml 37 | TestResult.xml 38 | 39 | # Build Results of an ATL Project 40 | [Dd]ebugPS/ 41 | [Rr]eleasePS/ 42 | dlldata.c 43 | 44 | # DNX 45 | project.lock.json 46 | project.fragment.lock.json 47 | artifacts/ 48 | 49 | *_i.c 50 | *_p.c 51 | *_i.h 52 | *.ilk 53 | *.meta 54 | *.obj 55 | *.pch 56 | *.pdb 57 | *.pgc 58 | *.pgd 59 | *.rsp 60 | *.sbr 61 | *.tlb 62 | *.tli 63 | *.tlh 64 | *.tmp 65 | *.tmp_proj 66 | *.log 67 | *.vspscc 68 | *.vssscc 69 | .builds 70 | *.pidb 71 | *.svclog 72 | *.scc 73 | 74 | # Chutzpah Test files 75 | _Chutzpah* 76 | 77 | # Visual C++ cache files 78 | ipch/ 79 | *.aps 80 | *.ncb 81 | *.opendb 82 | *.opensdf 83 | *.sdf 84 | *.cachefile 85 | *.VC.db 86 | *.VC.VC.opendb 87 | 88 | # Visual Studio profiler 89 | *.psess 90 | *.vsp 91 | *.vspx 92 | *.sap 93 | 94 | # TFS 2012 Local Workspace 95 | $tf/ 96 | 97 | # Guidance Automation Toolkit 98 | *.gpState 99 | 100 | # ReSharper is a .NET coding add-in 101 | _ReSharper*/ 102 | *.[Rr]e[Ss]harper 103 | *.DotSettings.user 104 | 105 | # JustCode is a .NET coding add-in 106 | .JustCode 107 | 108 | # TeamCity is a build add-in 109 | _TeamCity* 110 | 111 | # DotCover is a Code Coverage Tool 112 | *.dotCover 113 | 114 | # NCrunch 115 | _NCrunch_* 116 | .*crunch*.local.xml 117 | nCrunchTemp_* 118 | 119 | # MightyMoose 120 | *.mm.* 121 | AutoTest.Net/ 122 | 123 | # Web workbench (sass) 124 | .sass-cache/ 125 | 126 | # Installshield output folder 127 | [Ee]xpress/ 128 | 129 | # DocProject is a documentation generator add-in 130 | DocProject/buildhelp/ 131 | DocProject/Help/*.HxT 132 | DocProject/Help/*.HxC 133 | DocProject/Help/*.hhc 134 | DocProject/Help/*.hhk 135 | DocProject/Help/*.hhp 136 | DocProject/Help/Html2 137 | DocProject/Help/html 138 | 139 | # Click-Once directory 140 | publish/ 141 | 142 | # Publish Web Output 143 | *.[Pp]ublish.xml 144 | *.azurePubxml 145 | # TODO: Comment the next line if you want to checkin your web deploy settings 146 | # but database connection strings (with potential passwords) will be unencrypted 147 | #*.pubxml 148 | *.publishproj 149 | 150 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 151 | # checkin your Azure Web App publish settings, but sensitive information contained 152 | # in these scripts will be unencrypted 153 | PublishScripts/ 154 | 155 | # NuGet Packages 156 | *.nupkg 157 | # The packages folder can be ignored because of Package Restore 158 | **/packages/* 159 | # except build/, which is used as an MSBuild target. 160 | !**/packages/build/ 161 | # Uncomment if necessary however generally it will be regenerated when needed 162 | #!**/packages/repositories.config 163 | # NuGet v3's project.json files produces more ignoreable files 164 | *.nuget.props 165 | *.nuget.targets 166 | 167 | # Microsoft Azure Build Output 168 | csx/ 169 | *.build.csdef 170 | 171 | # Microsoft Azure Emulator 172 | ecf/ 173 | rcf/ 174 | 175 | # Windows Store app package directories and files 176 | AppPackages/ 177 | BundleArtifacts/ 178 | Package.StoreAssociation.xml 179 | _pkginfo.txt 180 | 181 | # Visual Studio cache files 182 | # files ending in .cache can be ignored 183 | *.[Cc]ache 184 | # but keep track of directories ending in .cache 185 | !*.[Cc]ache/ 186 | 187 | # Others 188 | ClientBin/ 189 | ~$* 190 | *~ 191 | *.dbmdl 192 | *.dbproj.schemaview 193 | *.jfm 194 | *.pfx 195 | *.publishsettings 196 | node_modules/ 197 | orleans.codegen.cs 198 | 199 | # Since there are multiple workflows, uncomment next line to ignore bower_components 200 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 201 | #bower_components/ 202 | 203 | # RIA/Silverlight projects 204 | Generated_Code/ 205 | 206 | # Backup & report files from converting an old project file 207 | # to a newer Visual Studio version. Backup files are not needed, 208 | # because we have git ;-) 209 | _UpgradeReport_Files/ 210 | Backup*/ 211 | UpgradeLog*.XML 212 | UpgradeLog*.htm 213 | 214 | # SQL Server files 215 | *.mdf 216 | *.ldf 217 | 218 | # Business Intelligence projects 219 | *.rdl.data 220 | *.bim.layout 221 | *.bim_*.settings 222 | 223 | # Microsoft Fakes 224 | FakesAssemblies/ 225 | 226 | # GhostDoc plugin setting file 227 | *.GhostDoc.xml 228 | 229 | # Node.js Tools for Visual Studio 230 | .ntvs_analysis.dat 231 | 232 | # Visual Studio 6 build log 233 | *.plg 234 | 235 | # Visual Studio 6 workspace options file 236 | *.opt 237 | 238 | # Visual Studio LightSwitch build output 239 | **/*.HTMLClient/GeneratedArtifacts 240 | **/*.DesktopClient/GeneratedArtifacts 241 | **/*.DesktopClient/ModelManifest.xml 242 | **/*.Server/GeneratedArtifacts 243 | **/*.Server/ModelManifest.xml 244 | _Pvt_Extensions 245 | 246 | # Paket dependency manager 247 | .paket/paket.exe 248 | paket-files/ 249 | 250 | # FAKE - F# Make 251 | .fake/ 252 | 253 | # JetBrains Rider 254 | .idea/ 255 | *.sln.iml 256 | 257 | # CodeRush 258 | .cr/ 259 | 260 | # Python Tools for Visual Studio (PTVS) 261 | __pycache__/ 262 | *.pyc -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Version 1.0.5473 2 | * Support for GTK, MAC and Tizen platform was added 3 | 4 | # Version 1.0.5463 5 | * Support for UWP platform was added 6 | 7 | # Version 1.0.5461 8 | * Support for Non-Repeatable execution of IPeriodicTask 9 | 10 | 11 | # Version 1.0.5460 12 | * [Android] Fixes for build and missing library issue 13 | * [iOS] Fixes for build and missing library issue 14 | 15 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 Winston Gubantes / Matcha LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Xamarin.Forms.Background (Background plugin for Xamarin.Forms) 2 | 3 | A plugin library to simplify Backgrounding in Xamarin.Forms. 4 | 5 | 6 | ## Get Started 7 | 8 | Ever wonder how facebook and twitter process there background to fetch a new content? And it looks so slick that when you refresh it was snappy and smooth, Making the user believed that the content is refreshed and updated in a snap when in fact it was done in the background. 9 | 10 | The secret behind it was the background service. And so we have created Xamarin.Forms.Background to make our backgrounding task be simple and maintenable. 11 | 12 | ## Build & Test Status 13 | 14 | * [![Build status](https://github.com/nblockchain/XamarinFormsBackground/workflows/ci/badge.svg)](https://github.com/nblockchain/XamarinFormsBackground/actions) 15 | 16 | ## Setup 17 | 18 | * NuGet: [Xamarin.Forms.Background](https://www.nuget.org/packages/Xamarin.Forms.Background) [![NuGet](https://img.shields.io/nuget/v/Xamarin.Forms.Background.svg?label=NuGet)](https://www.nuget.org/packages/Xamarin.Forms.Background/) 19 | * Install into ALL of your projects, including client projects. 20 | * Initialize `BackgroundAggregator` in each platform project. 21 | 22 | ### For Android 23 | You call the "Init" method before all libraries initialization in MainActivity class. 24 | 25 | ```csharp 26 | public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity 27 | { 28 | protected override void OnCreate(Bundle bundle) 29 | { 30 | BackgroundAggregator.Init(this); 31 | 32 | base.OnCreate(bundle); 33 | ....// Code for init was here 34 | } 35 | } 36 | ``` 37 | 38 | ### For iOS 39 | 40 | You call the "Init" method before all libraries initialization in FinishedLaunching method in FormsApplicationDelegate class. 41 | 42 | ```csharp 43 | public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate 44 | { 45 | public override bool FinishedLaunching(UIApplication app, NSDictionary options) 46 | { 47 | BackgroundAggregator.Init(this); 48 | 49 | ....// Code for init was here 50 | return base.FinishedLaunching(app, options); 51 | } 52 | } 53 | ``` 54 | 55 | ### For macOS 56 | 57 | You call the "Init" method before all libraries initialization in DidFinishLaunching method in FormsApplicationDelegate class. 58 | 59 | ```csharp 60 | public partial class AppDelegate : global::Xamarin.Forms.Platform.MacOS.FormsApplicationDelegate 61 | { 62 | public override void DidFinishLaunching(NSNotification notification) 63 | { 64 | BackgroundAggregator.Init(this); 65 | Forms.Init(); 66 | LoadApplication(new App()); 67 | base.DidFinishLaunching(notification); 68 | } 69 | } 70 | ``` 71 | 72 | ### For Tizen 73 | 74 | You call the "Init" method before all libraries initialization in OnCreate method in FormsApplication class. 75 | 76 | ```csharp 77 | class Program : global::Xamarin.Forms.Platform.Tizen.FormsApplication 78 | { 79 | protected override void OnCreate() 80 | { 81 | base.OnCreate(); 82 | BackgroundAggregator.Init(this); 83 | LoadApplication(new Sample.App()); 84 | } 85 | 86 | static void Main(string[] args) 87 | { 88 | var app = new Program(); 89 | global::Xamarin.Forms.Platform.Tizen.Forms.Init(app); 90 | app.Run(args); 91 | } 92 | } 93 | ``` 94 | 95 | ### For Gtk 96 | 97 | You call the "Init" method before all libraries initialization in Main method in MainClass class. 98 | 99 | ```csharp 100 | class MainClass 101 | { 102 | [STAThread] 103 | public static void Main(string[] args) 104 | { 105 | Gtk.Application.Init(); 106 | Forms.Init(); 107 | 108 | BackgroundAggregator.Init(); 109 | 110 | var app = new App(); 111 | var window = new FormsWindow(); 112 | window.LoadApplication(app); 113 | window.SetApplicationTitle("Game of Life"); 114 | window.Show(); 115 | 116 | Gtk.Application.Run(); 117 | } 118 | } 119 | ``` 120 | 121 | ### For UWP 122 | 123 | First, You call the "Init" method before all libraries initialization in MainPage class. 124 | 125 | ```csharp 126 | public sealed partial class MainPage 127 | { 128 | public MainPage() 129 | { 130 | this.InitializeComponent(); 131 | 132 | BackgroundAggregator.Init(this); 133 | 134 | LoadApplication(new SampleBackground.App(new UwpInitializer())); 135 | } 136 | } 137 | ``` 138 | 139 | Then you put the line "BackgroundAggregatorService.Instance.Start()" in OnBackgroundActivated method under App.cs of UWP project. 140 | 141 | ```csharp 142 | protected override void OnBackgroundActivated(BackgroundActivatedEventArgs args) 143 | { 144 | base.OnBackgroundActivated(args); 145 | BackgroundAggregatorService.Instance.Start(); 146 | } 147 | ``` 148 | 149 | ## Create Background Task 150 | 151 | You will have to inherit IBackgroundTask interface in which you will supply and implement the interval and StartJob. 152 | 153 | ```csharp 154 | public class SomeBackgroundWork : IBackgroundTask 155 | { 156 | public SomeBackgroundWork() 157 | { 158 | } 159 | 160 | public Task StartJob() 161 | { 162 | // YOUR CODE HERE 163 | 164 | return; 165 | } 166 | } 167 | ``` 168 | 169 | ## Register Background Task 170 | 171 | After you have implemented the Background Task you will need to register it to Background Aggregator Service. We define it on OnStart() method under App.cs. 172 | 173 | ```csharp 174 | protected override void OnStart() 175 | { 176 | //Register Background Tasks 177 | BackgroundAggregatorService.Add(() => new SomeBackgroundWork()); 178 | BackgroundAggregatorService.Add(() => new OtherBackgroundWork()); 179 | 180 | //Start the background service 181 | BackgroundAggregatorService.StartBackgroundService(); 182 | } 183 | ``` 184 | 185 | 186 | ## Quirks and Limitation 187 | 188 | Keep in mind that the plugin was not design to communicate with UI thread, one way of dealing the transfer of information is through storage (e.g. Sqlite or Settings plugin). Our sample project is using Monkey-Cache storage. 189 | 190 | Starting with Android Oreo it has already introduced the background execution limits similar to iOS background time limits assuming the app is in background mode or app is closed or minimized, as discuss on this [article](https://blog.xamarin.com/replacing-services-jobs-android-oreo-8-0/). 191 | 192 | UWP backgrounding uses In-Process backgrounding which is a bit less resilient than the Out-Process, however In-Process provides simplier approach and this is why we intend to support this platform using this approach. 193 | 194 | For recently supported Gtk Mac and Tizen are very straightforward it doesn't require native backgrounding, however it runs the task on a separate thread to immitate backgrounding process. 195 | 196 | For more info about Backgrounding in Android please check the link [HERE](https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/services/). 197 | 198 | For more info about Backgrounding in iOS please check the link [HERE](https://docs.microsoft.com/en-us/xamarin/ios/app-fundamentals/backgrounding/ios-backgrounding-techniques/). 199 | 200 | For more info about Backgrounding in UWP please check the link [HERE](https://docs.microsoft.com/en-us/windows/uwp/launch-resume/create-and-register-an-inproc-background-task). 201 | 202 | ## That's it 203 | 204 | You can now run your app that runs your Background Tasks in the Background Service. We have provided a few good samples to for you to dig in. 205 | 206 | ## Our Sample 207 | 208 | We have created a sample app that has 3 tasks in the background that get an RSS feed from news outlet like BBC News, CNN News and Washington Post. 209 | 210 | 211 | 212 | 213 | ## Platform Supported 214 | 215 | |Platform|Version| 216 | | ------------------- | :-----------: | 217 | |Xamarin.iOS|iOS 7+| 218 | |Xamarin.Mac|All| 219 | |Xamarin.Android|API 15+| 220 | |Windows 10 UWP|10+| 221 | |Tizen|4.0+| 222 | |Gtk|All| 223 | |.NET Standard|2.0+| 224 | -------------------------------------------------------------------------------- /Xamarin.Forms.Background.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Xamarin.Forms.Background 5 | 0.0.1 6 | A plugin library to simplify Backgrounding in Xamarin.Forms. 7 | Winston Gubantes 8 | knocte 9 | https://github.com/nblockchain/XamarinFormsBackground/blob/master/LICENSE.md 10 | https://github.com/nblockchain/XamarinFormsBackground/ 11 | https://github.com/winstongubantes/MatchaBackgroundService/blob/master/images/icon.png 12 | false 13 | 14 | BackgroundWorker abstraction that maps to native APIs for all platforms supported by Xamarin.Forms 15 | 16 | 17 | https://github.com/nblockchain/XamarinFormsBackground/commits/master 18 | 19 | A plugin library to simplify Backgrounding in Xamarin.Forms. 20 | xamarin, android, ios, backgroundservice 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /build.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | SET SLN=src\Xamarin.Forms.Background.sln 4 | CALL scripts\msbuild.bat /t:restore %SLN% && CALL scripts\msbuild.bat /t:build /p:Configuration=Release %SLN% 5 | -------------------------------------------------------------------------------- /images/newsfeed.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nblockchain/XamarinFormsBackground/9ac65563de95252eb4bd925e7ed9f84dc1a3bcb5/images/newsfeed.gif -------------------------------------------------------------------------------- /scripts/msbuild.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | SET ENTERPRISE="%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe" 4 | SET COMMUNITY="%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe" 5 | SET BUILDTOOLS="%ProgramFiles(x86)%\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe" 6 | 7 | IF EXIST %ENTERPRISE% ( 8 | SET RUNNER=%ENTERPRISE% 9 | ) ELSE ( 10 | IF EXIST %COMMUNITY% ( 11 | SET RUNNER=%COMMUNITY% 12 | ) ELSE ( 13 | IF EXIST %BUILDTOOLS% ( 14 | SET RUNNER=%BUILDTOOLS% 15 | ) ELSE ( 16 | ECHO msbuild.exe not found, is VS2019 installed? 17 | EXIT /b 1 18 | ) 19 | ) 20 | ) 21 | 22 | %RUNNER% %* 23 | -------------------------------------------------------------------------------- /src/SampleBackground/SampleBackground.Android/Assets/AboutAssets.txt: -------------------------------------------------------------------------------- 1 | Any raw assets you want to be deployed with your application can be placed in 2 | this directory (and child directories) and given a Build Action of "AndroidAsset". 3 | 4 | These files will be deployed with you package and will be accessible using Android's 5 | AssetManager, like this: 6 | 7 | public class ReadAsset : Activity 8 | { 9 | protected override void OnCreate (Bundle bundle) 10 | { 11 | base.OnCreate (bundle); 12 | 13 | InputStream input = Assets.Open ("my_asset.txt"); 14 | } 15 | } 16 | 17 | Additionally, some Android functions will automatically load asset files: 18 | 19 | Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf"); 20 | -------------------------------------------------------------------------------- /src/SampleBackground/SampleBackground.Android/MainActivity.cs: -------------------------------------------------------------------------------- 1 | using Android.App; 2 | using Android.Content.PM; 3 | using Android.OS; 4 | using Xamarin.Forms.Background; 5 | using Xamarin.Forms.Background.Android; 6 | using Prism; 7 | using Prism.Ioc; 8 | 9 | namespace SampleBackground.Droid 10 | { 11 | [Activity(Label = "SampleBackground", Icon = "@mipmap/ic_launcher", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] 12 | public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity 13 | { 14 | protected override void OnCreate(Bundle bundle) 15 | { 16 | TabLayoutResource = Resource.Layout.Tabbar; 17 | ToolbarResource = Resource.Layout.Toolbar; 18 | 19 | base.OnCreate(bundle); 20 | 21 | BackgroundAggregator.Init(this); 22 | 23 | global::Xamarin.Forms.Forms.Init(this, bundle); 24 | LoadApplication(new App(new AndroidInitializer())); 25 | } 26 | } 27 | 28 | public class AndroidInitializer : IPlatformInitializer 29 | { 30 | public void RegisterTypes(IContainerRegistry container) 31 | { 32 | // Register any platform specific implementations 33 | } 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /src/SampleBackground/SampleBackground.Android/Properties/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/SampleBackground/SampleBackground.Android/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | using Android.App; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | [assembly: AssemblyTitle("SampleBackground.Android")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct("SampleBackground.Android")] 14 | [assembly: AssemblyCopyright("Copyright © 2014")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | [assembly: ComVisible(false)] 18 | 19 | // Version information for an assembly consists of the following four values: 20 | // 21 | // Major Version 22 | // Minor Version 23 | // Build Number 24 | // Revision 25 | // 26 | // You can specify all the values or you can default the Build and Revision Numbers 27 | // by using the '*' as shown below: 28 | // [assembly: AssemblyVersion("1.0.*")] 29 | [assembly: AssemblyVersion("1.0.0.0")] 30 | [assembly: AssemblyFileVersion("1.0.0.0")] 31 | 32 | // Add some common permissions, these can be removed if not needed 33 | [assembly: UsesPermission(Android.Manifest.Permission.Internet)] 34 | [assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)] 35 | -------------------------------------------------------------------------------- /src/SampleBackground/SampleBackground.Android/Resources/AboutResources.txt: -------------------------------------------------------------------------------- 1 | Images, layout descriptions, binary blobs and string dictionaries can be included 2 | in your application as resource files. Various Android APIs are designed to 3 | operate on the resource IDs instead of dealing with images, strings or binary blobs 4 | directly. 5 | 6 | For example, a sample Android app that contains a user interface layout (main.xml), 7 | an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png) 8 | would keep its resources in the "Resources" directory of the application: 9 | 10 | Resources/ 11 | drawable-hdpi/ 12 | icon.png 13 | 14 | drawable-ldpi/ 15 | icon.png 16 | 17 | drawable-mdpi/ 18 | icon.png 19 | 20 | layout/ 21 | main.xml 22 | 23 | values/ 24 | strings.xml 25 | 26 | In order to get the build system to recognize Android resources, set the build action to 27 | "AndroidResource". The native Android APIs do not operate directly with filenames, but 28 | instead operate on resource IDs. When you compile an Android application that uses resources, 29 | the build system will package the resources for distribution and generate a class called 30 | "Resource" that contains the tokens for each one of the resources included. For example, 31 | for the above Resources layout, this is what the Resource class would expose: 32 | 33 | public class Resource { 34 | public class drawable { 35 | public const int icon = 0x123; 36 | } 37 | 38 | public class layout { 39 | public const int main = 0x456; 40 | } 41 | 42 | public class strings { 43 | public const int first_string = 0xabc; 44 | public const int second_string = 0xbcd; 45 | } 46 | } 47 | 48 | You would then use R.drawable.icon to reference the drawable/icon.png file, or Resource.layout.main 49 | to reference the layout/main.xml file, or Resource.strings.first_string to reference the first 50 | string in the dictionary file values/strings.xml. 51 | -------------------------------------------------------------------------------- /src/SampleBackground/SampleBackground.Android/Resources/layout/Main.axml: -------------------------------------------------------------------------------- 1 |  2 | 3 |