meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
android:basics [2012/07/04 17:06] – created esa-petriandroid:basics [2012/07/04 19:10] (current) esa-petri
Line 1: Line 1:
 =====Android basics===== =====Android basics=====
-some cool wise sounding text here+First thing to do before starting making your android program is plan. here things you need to know before you start coding anything: 
 +   * What your program is. Is it calculator or game or what? 
 +   * what functionality it needs. does it play sound, does it need acceleration or fancy graphics 
 +   * how to divide it in functional different classes and does it use patterns. [[http://obviam.net/index.php/the-mvc-pattern-tutorial-building-games/|Notice MVC pattern is good for games]] 
 +   * decide does it need many Activities or views and if so how they communicate and are related 
 +   * now calculated time needed and multiply whit pi. if it takes too much reduce functionality. 
 +   * find core functionality and bare basic that are needed and implement them 
 +   * if time was let from previous one, implement all rest fancy stuff you planed originaly
  
 ===Layouts=== ===Layouts===
 +When building Gui it is important to choose right layout. while using linear layouts is easy they are very restrictive. Relative in other hand is way to get complicated designs but need often small changes to xml. I suggest to use Realative Layout as default. 
 +you should always when you create elements change their default name to something human readable. to do this right click element and select edit id. Do this every time you create element(or you will suffer horrible problems buhahaa....). 
 +Text of elements should be placed inside project/res/values/Strings.xml (remember that)
  
 +Things that you find your self adding by hand to xml are.
 +  * android:layout_centerHorizontal="true"
 +  * android:layout_centerVertical="true"
 +to get element centered
 +  * android:onClick="onSaveButtonClick"
 +to add click listening to buttons,togglebuttos and pretty much everything
 +and sizes/position of elements are easier to fine-tune from xml
  
 links: links:
    * http://developer.android.com/guide/topics/ui/declaring-layout.html    * http://developer.android.com/guide/topics/ui/declaring-layout.html
 +   * http://www.learn-android.com/2010/01/05/android-layout-tutorial/
  
 ===Icons and resources=== ===Icons and resources===
-your android project has resources in res folder. you can add resources by manually editing files in case of res/values/strings that is rather suitable and easy+your android project has resources in res folder. you can add resources by manually editing files in case of res/values/strings that is rather suitable and easy.  
 +you can add new icons by creating new iconbutton and changing its background and there is choice for creating new image resource. but often easiest choice is copying image to project/res/drawable-* folders and android will resize it when used. notice that too big resolution make your program slow.
  
 Links: Links:
Line 15: Line 34:
  
 === AndroidManifest.xml === === AndroidManifest.xml ===
-often manifest file is missing your brand new Activity or you haven't set permissions there, So keep close eye on this file as it causes you lots of problems if you don't+Often when your program doesn't start Activities manifest file is missing your brand new Activity or you haven't set permissions there, So keep close eye on this file as it causes you lots of problems if you don't. Remember give permission to you program from there.
  
 +links:
 +   * http://developer.android.com/guide/topics/manifest/manifest-intro.html
 +   * http://developer.android.com/tools/publishing/versioning.html
 +
 +=== Debugging ===
 +Next line of code is used to get android print conveniently to debugger.
 +Tag is name of class or anything you want, message is message(daa). 
 +        log.d("Tag","message");
 +
 +code line to turn some policy restrictions to errors
 +
 + private static final boolean DEVELOPER_MODE = true;
 + private static final String TAG = "GameActivity";
 + private static final int SDK_VERSION = android.os.Build.VERSION.SDK_INT;
 + if (DEVELOPER_MODE && SDK_VERSION > 13) {
 + StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
 + .detectDiskReads().detectDiskWrites().detectNetwork()
 + .penaltyLog().build());
 + StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
 + .detectLeakedSqlLiteObjects().detectLeakedClosableObjects()
 + .penaltyLog().penaltyDeath().build());
 +                        log.d(TAG,"developer mode is on")
 + }
 +
 +
 +links:
 +   * http://developer.android.com/reference/android/util/Log.html
 +   * http://stackoverflow.com/questions/3773252/log-d-and-impact-on-performance
  
  
Line 26: Line 73:
   * AndroidManifest.xml   * AndroidManifest.xml
   * and check resource files   * and check resource files
- 
- 
-