locked
How to temporarily store data in application memory ? RRS feed

  • Question

  • User204688 posted

    How to temporarily store data in application memory ,so that it does not get saved when the application is restarted

    Friday, February 26, 2021 6:46 AM

Answers

  • User371688 posted

    Do you want to save some value and access it within the scope of your application?

    If yes, you can use static variable to achieve this. For example, if we define a static variable TotalNumber in App.xaml.cs as follows:

         public partial class App : Application
    {
       // define a variable TotalNumber 
        public static int TotalNumber = 0;
        public App()
        {
            InitializeComponent();
    
            MainPage = new MainPage();
        }
    

    }

    Then we can access this variable in other class in this way:

            App.TotalNumber = 12;
            App.TotalNumber++;
            System.Diagnostics.Debug.WriteLine("TotalNumber = " + App.TotalNumber);
    

    And when you close the app,the memory of this variable will been released.


    Xamarin forums are migrating to a new home on Microsoft Q&A! We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A! For more information, please refer to this sticky post.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, February 26, 2021 8:04 AM
  • User371688 posted

    is it right way to secure Master Password?

    This is usually used to store the value of an app's variables. Once the application is closed, the variable memory is reclaimed. If you use this method to store passwords, this is probably not a good idea. If you store your password this way, and if someone gets your phone and uses your app, they can still do all kinds of things.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, February 26, 2021 9:31 AM

All replies

  • User371688 posted

    Do you want to save some value and access it within the scope of your application?

    If yes, you can use static variable to achieve this. For example, if we define a static variable TotalNumber in App.xaml.cs as follows:

         public partial class App : Application
    {
       // define a variable TotalNumber 
        public static int TotalNumber = 0;
        public App()
        {
            InitializeComponent();
    
            MainPage = new MainPage();
        }
    

    }

    Then we can access this variable in other class in this way:

            App.TotalNumber = 12;
            App.TotalNumber++;
            System.Diagnostics.Debug.WriteLine("TotalNumber = " + App.TotalNumber);
    

    And when you close the app,the memory of this variable will been released.


    Xamarin forums are migrating to a new home on Microsoft Q&A! We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A! For more information, please refer to this sticky post.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, February 26, 2021 8:04 AM
  • User204688 posted

    @jezh thanks for your explanation .is it right way to secure Master Password?

    Friday, February 26, 2021 9:09 AM
  • User371688 posted

    is it right way to secure Master Password?

    This is usually used to store the value of an app's variables. Once the application is closed, the variable memory is reclaimed. If you use this method to store passwords, this is probably not a good idea. If you store your password this way, and if someone gets your phone and uses your app, they can still do all kinds of things.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, February 26, 2021 9:31 AM
  • User371688 posted

    Hi @D_R ,have you resolved your problem? If my reply is useful for you, could you please mark it as answered? Thanks in advance. :)

    Monday, March 1, 2021 1:41 AM