1

In my project I am to provide some functions which can be provided using session and application variable like in c#. MY information is confidential so can not be stored in files like xml Thanks in advance.

Edit : 1- Solution for session variable i've found called sharedpreference but don't know how to use please tell me

  • how to initiallize it and
  • set it from other class and
  • get the value from some other?

    ?...?...?..

Trikaldarshiii
  • 11,174
  • 16
  • 67
  • 95
  • SharedPreferences is (*stored in xml format and*) also readable and can be found and explored, [see here](http://stackoverflow.com/a/2566613/593709) and [here](http://stackoverflow.com/a/6146207/593709) since you said info is confidential. – Adil Soomro May 21 '12 at 05:27

2 Answers2

2

First of all, your application can basically die at any time, because it can be killed off by the Android scheduler after your app sits in the background for a while and the platform needs more memory.

That being said, storing your data in a global Application class is generally considered a bit hacky. Instead, the way you use this depends on how you are going to access the application. It's a pretty commonly accepted thing that a lot of apps keep things like their OAuth tokens in SharedPreferences (though I'm not sure exactly how kosher this is). What you might do is keep your session variable in an Application class, and then -- whenever the app dies -- simply reauthenticate. This is probably good practice anyway, as after that long someone may have picked up the phone, etc...

However, you seem to be under the impression that SharedPreferences can be read by anyone. This is incorrect, see this. Now, if you have a rooted phone, sure, then there's a way around that, but this is always going to be an issue, on a rooted phone you should basically consider that you don't really have any security at all...

Kristopher Micinski
  • 7,572
  • 3
  • 29
  • 34
0

Application class is there for you. use it and save your application level data, like this:

public class WhatEverApp extends Application
{
    String mApplicationLevelVar = "Hello";
}

WhatEverApp will be the name of your app used in manifest.xml

Look here for detailed discussion on Application class.

Community
  • 1
  • 1
Adil Soomro
  • 37,609
  • 9
  • 103
  • 153