Thursday, March 24, 2011

[android-developers] Re: Android Application Settings Problems

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.*;
import android.view.View.*;
import android.widget.*;

/*
*
* @author Matt
*/
public class MainActivity extends Activity {

//public static final String APP_PREFS = "ScoutingDataBase_Prefs";
public EditText txtIp1, txtIp2, txtIp3, txtIp4;
public Button btnConnect;

public SharedPreferences settings =
getSharedPreferences("AppSettings", 0);

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);

boolean savedsetting = settings.getBoolean("savedBool",
false);
...
...
}

I found on Android Developer that this is what one would use to create
and use a settings file with their application.
~Matt

On Mar 24, 12:46 am, kiran <saikiran....@gmail.com> wrote:
> Could you provide log cat error message or some more detailed code
> what you are executing.
> Because the piece of code you wrote some what confusing me
> public SharedPreferences settings = getSharedPreferences(PREFS_NAME,
> 0);
>
> On Mar 24, 9:19 am, MattClark <mrclark32...@gmail.com> wrote:
>
>
>
>
>
>
>
> > I am trying to use application preferences in my app, following this
> > at AndroidDevelopes:http://developer.android.com/guide/topics/data/data-storage.html
>
> > my code is as follows.
>
> > imports:
> > import android.content.SharedPreferences;
>
> > declarations:
> > public String PREFS_NAME = "MyAppSettings";
> > public SharedPreferences settings = getSharedPreferences(PREFS_NAME,
> > 0);
>
> > the program compiles fine, but when i deploy it to my device it errors
> > only if the second line of declarations is in place. I have no idea
> > what the problem is. i have tried (PREFS_NAME, 0)("MyAppSettings", 0)
> > ("PREFS_NAME, MODE_PRIVATE)("MyAppSettings", "MODE_PRIVATAE") and
> > every time it still errors on the device.
> > any and all help is greatly appreciated.
> > thanks
> > ~Matt

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment