Skip to main content

Featured

Android studio “SDK tools directory is missing”

Following 2 possible solutions will resolve this problem :  Solution1 : To fix the problem, it was required that I list the path to my corporate PAC file by using  Configure -> "Appearance and Behavior" -> System Settings -> HTTP Proxy . I selected "Automatic proxy configuration url:" Delete your  ~/.Android*  folders (losing all of your settings :/). Run Android Studio. It will show you a welcome wizard where it tries to download the SDK again (and fails due to my rubbish internet). Click the X on the wizard window. That will enable you to get to the normal welcome dialog. Go to Settings->Project Defaults->Project Structure and change the Android SDK location to the correct one. Solution 2 : To fix the problem, it was required that I list the path to my corporate PAC file by using  Configure -> "Appearance and Behavior" -> System Settings -> HTTP Proxy . I selected "Automatic proxy configuration url:&quo

Complete Code to use SharedPreferences,in NonActivity class,in Android

public class SharedPrefrence extends Activity {
    //Complete Code to use SharedPreferences,in NonActivity class,in Android
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        //simple code for storing a String in SharedPreferences method of NonActivity class and get it and finally display it. 
        String userName="pavan tilak";       
        SharedPrefMethod Obj=new SharedPrefMethod(this);
        //Obj.SharedMethod(s);
       
        //pass a String to a method exists in NonActivity class for storing it in SharedPreference
        SharedPreferences shared = Obj.SharedMethod(userName);
        String uname = shared.getString("my_name", null);      
        System.out.println("****sharedValue**"+uname);
}}


------------------------------------------------------------------------------------------------------------

public class SharedPrefMethod {
   
    Context myContext;
    SharedPreferences sharedVariable;
   
    SharedPrefMethod(Context cntxt){
        myContext=cntxt;
    }
   
    //method for storing single String value in sharedPreferences
    public SharedPreferences SharedMethod(String str){
       
         SharedPreferences settings = myContext.getSharedPreferences("str",0);
         SharedPreferences.Editor editor = settings.edit();

         editor.putString("my_name",str);
         editor.commit();
          
        return settings;
       
    }}

Comments