Posts by Chang Park

HttpURLConnection vs. HttpsURLConnection

java.net.HttpURLConnection

  • A URLConnection with support for HTTP-specific features
  • It can cover Https addresses also, because HttpsURLConnection extends this.
URL url = new URL("https://www.google.com/");

// HttpURLConnection can cover https URL.openconnection()
// because, HttpsURLConnection extends HttpURLConnection.
HttpURLConnection urlconnection = (HttpURLConnection) URL.openConnection();
try{
   Inputstream in  = new BufferdInputStream(urlconnection.getInputStream());
   readstream(in)
}finally{
   urlconnection.disconnect();
}

javax.net.ssl.HttpsURLConnection

  • HttpsURLConnection extends HttpURLConnection with support for https-specific features such as SSL
  • If HttpsURLConnection use same methods in HttpURLConnection(parent class), it super calls the methods from HttpURLConnection.

Break & Continue

break

  • Totally exit from loop(for,while,do~while) or from switch.

Example…

publc class example{
   public static void main(String[] args){
      int count = 1;
      while(true){
         if(count>3){ 
            break;
         }

         System.out.println(Integer.toString(count)+"th String printed lol");
         count++;
      }
   }
}

Output…

1th String Printed lol
2th String Printed lol
3th String Printed lol

continue

  • exit only current turn from loop(for,while,do~while), move onto next step in the loop.
publc class example{
   public static void main(String[] args){
      int count = 1;
      while(true){
         if(count%2==0){ 
            continue;
         }

         System.out.println(Integer.toString(count)+"th String printed lol");
         count++;
      }
   }
}

Output…

1th String Printed lol
3th String Printed lol
5th String Printed lol
...

Multidex for 64K limit problem

about

  • Android app originally designed with limit of 64K methods.
  • As app became bigger, android developer supported multidex for this problem.
  • So to use a lot of methods, you need to use Multidex in the code.

how to

Gradle configuration

android{
   ...
   defaultConfig{
      ...
      multiDexEnabled true
      ...
   }
   ...
}

Dependencies configuration in Gradle

dependencies{
   ...
   compile 'com.android.support:multidex:1.0.0'
   ...
}

AndroidManifest.xml   file Configuration

<application
   android:name="android.support.multidex.MultiDexApplication"
   ...>
   ...
</application>

 

Git Basic

Git

  • Git is a version control system that is used for software development and other version control tasks.
  • A repository to backup files and to update the files. So, you can use it later for restore or update.
  • You probably had a experience that you updated some shared filed and replace it, but actually you erased all the parts which others made updates. This is a common situation during working on a software development as a team.
  • If you use Git, it will ask you whether you really want to replace the file when there is an updated file by others.

Screen Shot 2016-07-19 at 4.27.12 PM

Repository

  • Remote repository: files are managed by remote repository server, and this is for sharing with others.
  • Local repository: personal repository that file is saved on my PC .

Screen Shot 2016-07-19 at 4.26.35 PM

Creating Repository

  • You can either create a brand new repository from scratch or by cloning an existing remote repository onto your local machine.

Screen Shot 2016-07-19 at 4.28.48 PM

Commit

Screen Shot 2016-07-19 at 4.37.15 PM

  • The “commit” operation enables you to record changes that were made to a file or directory in the Git history.
  • By commiting every change made, you will be able to view all changes chronologically in the respective file or directory.

Screen Shot 2016-07-19 at 4.38.02 PM

Working Tree and Index

Screen Shot 2016-07-19 at 4.41.29 PM

  • A “working tree” consist of files that you are currently working on.
  • An “index” is a staging area where new commits are prepared. It acts as the interface between a repository and a working tree.

  • Changes made on the working tree will not be commited directly to the repository. They need to be staged on the index first

Git Hub vs. Git Lab

GitHub

  • suitable for OpenSource project
  • extra fee is needed for private repository, not suitable for personal project.

Screen Shot 2016-07-19 at 4.46.30 PM

GitLab

  • free for using private repository.
  • If you pay extra, you can get technical support as well.

Screen Shot 2016-07-19 at 4.48.39 PM

Citation

Images and most of words are from the website below

  • https://backlogtool.com/git-guide/en/

 

What is enum and When to use

enum

  • Enum is a predefined list of values which do not represent some kind of numeric or textual data.
  • You can use enums when a variable can only take one out of a small set of possible values. Examples will be like type days(“Mon”,”Tue”,”Wed”,”Thu”,”Fri”,”Sat”,”Sun”).

enum days{

MON, TUE, WED, THU, FRI, SAT, SUN

}

Example

public class EnumExample {
   public enum Day {
      MON, TUE, WED, THU, FRI, SAT, SUN
   }
   Day dName;

   public EnumExample(Day dName) {
      this.dName = dName;
   }

   public void dayFeelings () {
      switch (dName) {
         case MON:
            System.out.println("Week starts :(");
            break;

         case SAT: case SUN:
            System.out.println("Weekend Yay!");
            break;

         default:
            System.out.println("Waiting for weekend…");
            break;
      }
   }

   public static void main(String[] args) {
      EnumExample mon = new EnumExample(Day.MON);
      mon.dayFeelings();
      EnumExample tue = new EnumExample(Day.TUE);
      tue.dayFeelings();
      EnumExample sat = new EnumExample(Day.SAT);
      sat.dayFeelings();
      EnumExample thu = new EnumExample(Day.THU);
      thu.dayFeelings();
   }
}

Output….

Week starts 🙁
Waiting for weekend…
Weekend Yay!
Waiting for weekend…

 

Important points

You can not assign any value other than specified in Enum Constants.

enum Color{
   YELLOW, GREEN, RED
}

Color c = Color.RED;
c = 1;           // Compilation Error

MyEnum.values() returns an array of MyEnum’s values

public class EnumExample{
   public enum Color{
      YELLOW(10), GREEN(20), RED(30);
      private int value;
      private Color(int value){
         this.value=value; 
      }
   }

   public static void main(String[] args){
      for(Color c: Color.values()){
         System.out.println("Color value: "+c.value+" Color name: "+c);
      }
   }

output…

Color value: 10 Color name: YELLOW
Color value: 20 Color name: GREEN
Color value: 30 Color name: RED

 

adb on terminal

adb

  • In Android/sdk/platform-tools, there is adb call.

adb1

adb devices

  • able to see connected device
  • on mine, emulator is running as shown

adb2

adb shell

  • connects to your device
  • Can look up all the files on the device
  • exit: to come out

adb3

adb logcat

  • way to check logcat on terminal
  • ctrl+ c : to exit
  • V is the lowest priority. If we pick V, it will get all the data V and above.(V,D,I,W,E,F,S)
  • S is the highest priority

adb4

  • adb logcat TEST:D
    • gets all logcat which tag is TEST and above debug

adb5

vi .bash_profile

  • on here we can set PATH. So, I don’t need to get into the specific directory to do a job(ex. adb call)

bash1

  • If you add this line to bash_profile, Path automatically sets as shown below

bash2

  • Now, you can call adb on everypath where you are on

bash3

Android File Components

Manifest

  • Describes what the application is about
  • activities
  • Android studio auto save the contents to here
  • Best place to check what’s going on the appManifest

Gradle file (Module)

  • Defines build dependencies , configurations

Gradle

  • minSdkVersion:
    • minimum version of android which can use this app
    • 18 and below cannot use this app
  • targetSdkVersion:
    • highest version of android which can use this app
  • versionCode:
    • version of the app
    • 1,2,3,4
  • versionName:
    • you can name version name on your own
    • 1.0.2 or 2.34

Drawable

  • Can have images which will be linked with android code
  • ldpi – low resolution
  • mdpi – middle resolution
  • hdpi – high resolution

Drawable

Layout Directory

  • Contains layout files for the android project

Layout

Menu Directory

  • Holds the menu layout files for use in android project

Menu

Value Directory

  • Each file contains each list of simple values that we can use for the application

Value1 Value2

 

Architecture Breakdown

androidArchitectureReal

Linux Kernel

  • Interacts with Android hardware and contains all the essential hardware drivers. Also provides abstraction layer between software and hardware

Libraries

  • Core proven libraries that handle specific types of data. Some examples include, SQLite, Surface Manager, Media Framework, Webkit, and OpenGL.

Android Runtime

  • The type of Java Virtual Machine used in android to run android applications. Optimized for low processing power and low memory environments

Application Framework

  • Building blocks that our application directly interact with. These programs manage basic functions of the phone such as phone calls, and resource management.

Applications

  • Programs that utilize all of the above to create new functionality for our devices

onCreate(), Activity, Bundle

Life cycle of activity

activity

  • entire lifetime
    • happens between the first call to onCreate(Bundle)through to a single final call to onDestroy()
  • visible lifetime
    • happens between a call to onStart() until a corresponding call to onStop(). During this time the user can see the activity on-screen, though it may not be in the foreground and interacting with the user.
  • foreground lifetime
    • happens between a call to onResume() until a corresponding call to onPause(). During this time the activity is in front of all other activities and interacting with the user. An activity can frequently go between the resumed and paused states

 

  • onCreate() – Called when the activity is first created. This is where you should do all of your normal static set up: create views, bind data to lists, etc.
    • setContentView
  • onRestart() – Called after your activity has been stopped, prior to it being started again. Always followed by onStart()
  • onStart() – Called when the activity is becoming visible to the user. Followed by onResume() if the activity comes to the foreground, or onStop() if it becomes hidden.
  • onResume() – Called when the activity will start interacting with the user. At this point your activity is at the top of the activity stack.
  • onPause() – Called when the system is about to start resuming a previous activity. This is typically used to commit unsaved changes to persistent data, stop animations and other things that may be consuming CPU.
  • onStop() – Called when the activity is no longer visible to the user, because another activity has been resumed and is covering this one.
  • onDestroy() – The final call you receive before your activity is destroyed. This can happen either because the activity is finishing

 

  • bundle in onCreate parameter
    • gives information when creating activity
    • Initially set to null
    • In the case that calling onCreate method after onStop(), and also it was killed not intentionally, it gives current status information for onCreate()

 

  • setContentView()
    • sets actual view which users will see
  • onSaveInstanceState(Bundle)
    • called when activity abnormally becomes onStop() state
    • store instance status information
    • When activity is being initialized again, calls the bundle information which onSaveInstanceState() had saved.
  • onRestoreInstanceState(Bundle)
    • called when activity abnormally becomes onStop() state and becomes back onResume() state