Protecting Sensitive Data in the Background in Xamarin.Forms | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (179).NET Core  (29).NET MAUI  (214)Angular  (110)ASP.NET  (51)ASP.NET Core  (83)ASP.NET MVC  (90)Azure  (41)Black Friday Deal  (1)Blazor  (226)BoldSign  (15)DocIO  (24)Essential JS 2  (109)Essential Studio  (200)File Formats  (68)Flutter  (133)JavaScript  (226)Microsoft  (120)PDF  (81)Python  (1)React  (105)Streamlit  (1)Succinctly series  (131)Syncfusion  (942)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (52)Windows Forms  (61)WinUI  (71)WPF  (163)Xamarin  (161)XlsIO  (38)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (9)Business intelligence  (55)Button  (4)C#  (157)Chart  (140)Chart of the week  (54)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (70)Development  (658)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (7)Essential Tools  (14)Excel  (43)Extensions  (22)File Manager  (7)Gantt  (19)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (512)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (54)Security  (4)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (14)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (393)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (614)What's new  (333)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Protecting sensitive data in Xamarin Forms app

Protecting Sensitive Data in the Background in Xamarin.Forms

Information security is as simple as ABC: always be careful.


Nowadays, mobile applications have become our daily bread. They are essential tools for developing our digital lives. We do everything through apps. We manage our bank accounts, listen to music, inform ourselves, read the news, share on social networks, and so on.

We know that we use each application for our convenience, but every time we install a new one, are we aware of the permissions we will grant it? That is, do we know the security level of any application?

I imagine everyone’s answer is a resounding no. And what we do know is that comfort and safety are antagonistic: the higher one is, the lower the other, and vice versa.

Privacy by default

The concept of privacy by default means that applications, software, or systems, from the moment they are created, should take measures to protect a user’s information (i.e. they should provide a data security facility).

For this, there are already methodologies that review the application code itself and provide guidelines for security, including data encryption, SSL-TLS protocols, vulnerability tests, audits, authentication mechanisms, storage, etc.

Just a few…

Certain applications have recently improved their features regarding the security they offer to users, such as PayPal, WhatsApp, and of course all banking applications. If we pay attention to any of them, we can see that they have a function to protect confidential information in the background.

But how do they do it?

The answer is super simple, so let’s see how we can do it in our Xamarin.Forms applications.

Let’s start with iOS

To protect our confidential information on Apple devices, we should go to the AppDelegate.cs file and enter the following methods:

  • OnResignActivation – Helps us block the content.
  • OnActivated – Helps us unlock the content.

Refer to the following code example.

using UIKit;
using Foundation;
using System.Linq;
namespace SensitiveData.iOS
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
        public override void OnResignActivation(UIApplication application)
            var blurEffect = UIBlurEffect.FromStyle(UIBlurEffectStyle.ExtraDark);
            var blurEffectView = new UIVisualEffectView(blurEffect)
                Frame = application.KeyWindow.Subviews.First().Bounds,
                AutoresizingMask = UIViewAutoresizing.FlexibleDimensions,
                Tag = 12
        public override void OnActivated(UIApplication uiApplication)
            var sub = uiApplication.KeyWindow?.Subviews.Last();
            if (sub == null)
            foreach (var vv in sub.Subviews)
                if (vv.Tag == 12)
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
            LoadApplication(new App());
            return base.FinishedLaunching(app, options);

On Android

Now for Android, we need to go to the MainActivity.cs file and do practically the same thing we did for iOS but in the OnPause and OnResume methods, like in the following code:

protected override void OnResume()
protected override void OnPause()
    Window.SetFlags(WindowManagerFlags.Secure, WindowManagerFlags.Secure);


Protecting Sensitive Data in iOS
Protecting Sensitive Data in Android
Images Source: Vicente Guzman GitHub

GitHub Reference: You can download the full code from GitHub.


For developers, application user’s data can be protected by following the steps provided in this blog post.

For the mobile application users, it is clear that if they want to protect their privacy and make their data safe (or less exposed), they must, in addition to reviewing the permissions of each application one by one, sacrifice comfort a little and perform a couple (or a few) more clicks instead of leaving all the settings as the developers of those apps would like them to be: 100% accessible.

So, use the tips given in this post and safeguard your sensitive data from unauthorized persons.

Happy coding!

About Syncfusion

Syncfusion offers over 150 UI controls for Xamarin, from basic editors to powerful, advanced controls like the DataGrid, Charts, ListView, and RTE controls. Use them to build charming applications!

If you want to send us feedback, please use the comments section below. You can also reach us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

If you like this post, we think you will also like the following:


Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed