Showing posts with label android studio. Show all posts
Showing posts with label android studio. Show all posts

Tuesday, November 15, 2016

Android : Context

Context 

Context = Current Screen

Assuming MainActivity is currently being displayed on the screen it will hold the context.If any other method require context ,  than needs to be passed as an argument as "MainActivity.this" and receiving method receives as (Context c)

Synatx:
Method_name(ParentClass.this); // assuming ParentClass holding the context

public void Method_name(Context c){
}

Eg : 
public class MainActivity extends AppCompatActivity {

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

       DBOperations oDBOperations=new DBOperations(MainActivity.this);
       oDBOperations.get_db_location(MainActivity.this);

    }
}

public class DBOperations {

    SQLiteOpenHelper sql_helper;
    DBOperations(Context context){
        sql_helper=new sqllitehelperclass(context);
    }
 
 public void get_db_location(Context c){
        String dbname = "mydb.db";
        Log.d("db path",c.getDatabasePath(dbname).toString());
    }
}

Tuesday, November 8, 2016

Android :Android Studio initial setup

Android Studio initial setup


Add below in build.gradle
android{
    repositories {
    maven { url 'http://repo1.maven.org/maven2' }
}
 
Add below in gradle.properties file
compile="com.android.support\:AppCompactActivity-v7.22.1.0" 

Android Studio: Set proxy Settings

Android Studio: Set proxy Settings


  1. From the menu bar, click File > Settings (on a Mac, click Android Studio > Preferences).
  2. In the left pane, click Appearance & Behavior > System Settings > HTTP Proxy. The HTTP Proxy page appears.

Or in your project , You will see "try Again" link.From here you can set the proxy

Android :make Android Studio work faster Offline

Make Android Studio work faster Offline


  1. File >Settings >Build,execution,Deployment>Compiler>In Command-line Options enter "--offline" without quotes
  2. File >Settings >Build,execution,Deployment>Gradle>Check "Offline Work" checkbox
  3. Press Apply and Ok
  4. In your Project>gradle Scripts>gradle.properties>add lines
org.gradle.daemon=trueorg.gradle.parallel=true

Sunday, March 1, 2015

Android : Change SDK in Android Studio

Change SDK in Android Studio


To do this, on the menu choose File -> Project Structure. Select the Libraries option and click the green + to add your library.

Saturday, February 28, 2015

Android :How to auto import the necessary classes in Android Studio with shortcut?

Android :How to auto import the necessary classes in Android Studio with shortcut?


Go to File -> Settings -> Editor -> Auto Import -> Java and make the below things:
Select Insert imports on paste value to All
Do tick mark on Add unambigious imports on the fly option and "Optimize imports on the fly*


 Screenshot