android mypractices

Post on 17-May-2015

640 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

Talk from Android Developer Days and Istanbul GTUG (GDG) meetings.

TRANSCRIPT

Android Best PracticesMurat Yener, eteration

Wednesday, May 23, 12

Android Best PracticesMurat Yener, eteration

Wednesday, May 23, 12

Android Best PracticesMurat Yener, eteration

Wednesday, May 23, 12

Android Best PracticesMurat Yener, eteration

Wednesday, May 23, 12

Why am I doing this talk?

Get well soon Alain!!

Wednesday, May 23, 12

Alternatives

• Make me look like Alain?

• or just let me do another talk...

Wednesday, May 23, 12

Alternatives

• Make me look like Alain?

• or just let me do another talk...

Wednesday, May 23, 12

pointed ears

science officer

half human - half vulcan

trying to understand human nature

rounded ears

developer

half flex - half java

trying to understand objective-c behaviour

Wednesday, May 23, 12

how to develop?

• Android SDK: Java, capable, resources, easy

• Android NDK: Most capable but??

• Adobe AIR: easy XML+AS but??!!

• runtime, memory, new apis

• Web+JS

Wednesday, May 23, 12

SDK

• Activities

• Services

• Widgets

• Intents&Broadcasts

• Preferences

Wednesday, May 23, 12

Going to Market

• Silence my Phone vs Shake to Answer

• idea

• target devices

• code right

• let users communicate with you

• respond back... (even when you don’t care)

Wednesday, May 23, 12

Targeting all devices

• Matching everyone is winner!

• bug!! v5 thinks its v6

• canary pattern

Wednesday, May 23, 12

Targeting all devices

• Matching everyone is winner!

• bug!! v5 thinks its v6

• canary pattern

Wednesday, May 23, 12

Targeting all Devices

• Never, ever manipulate images!!!

• Ok, only if you must...

• nine-patches

Wednesday, May 23, 12

Targeting all Devices

• Never, ever manipulate images!!!

• Ok, only if you must...

• nine-patches

Wednesday, May 23, 12

Targeting all Devices

• Never, ever manipulate images!!!

• Ok, only if you must...

• nine-patches

Wednesday, May 23, 12

Targeting all Devices

• Never, ever manipulate images!!!

• Ok, only if you must...

• nine-patches

Wednesday, May 23, 12

app fitness

• Collect you own trash!

• Services, unregister whatever registered

• Images: image=null != image.recycle();

• favor primitives over objects

• BUT!! avoid autoboxing

• keep in mind Generics only work for objects

• size checks on loops

Wednesday, May 23, 12

things that take time

• Specially when network is involved

• Never, ever lock up UI thread!!!

• Painless threading: Use AsyncTasks

• Let user know: Toaster

Wednesday, May 23, 12

Responsive UI

• use as little as possibles views in views: slower layout, drawing, startup time...

• cut down view hierarchy: memory, slow, StackOverFlowException

Wednesday, May 23, 12

Less Views??

• use Merge as root tag for components

• use RelativeLayout instead of LinearLayout

Wednesday, May 23, 12

class AndroidWay extends Activity {     TextView name;     ImageView thumbnail;     LocationManager loc;     Drawable icon;     String myName;

    public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);        name      = (TextView) findViewById(R.id.name);         thumbnail = (ImageView) findViewById(R.id.thumbnail);         loc       = (LocationManager) getSystemService(Activity.LOCATION_SERVICE);         icon      = getResources().getDrawable(R.drawable.icon);         myName    = getString(R.string.app_name);         name.setText( "Hello, " + myName );     } } class RoboWay extends RoboActivity {     @InjectView(R.id.name)             TextView name;     @InjectView(R.id.thumbnail)        ImageView thumbnail;     @InjectResource(R.drawable.icon)   Drawable icon;     @InjectResource(R.string.app_name) String myName;     @Inject                            LocationManager loc;

    public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);        name.setText( "Hello, " + myName );     } }

DI in Android!!

• findViewById is expensive!

• either use it once or... RoboGuice!!

Wednesday, May 23, 12

...

Wednesday, May 23, 12

@EActivity(R.layout.translate) // Sets content view to R.layout.translatepublic class TranslateActivity extends Activity { @ViewById // Injects R.id.textInput EditText textInput;

@ViewById(R.id.myTextView) // Injects R.id.myTextView TextView result;

@AnimationRes // Injects android.R.anim.fade_in Animation fadeIn;

@Click // When R.id.doTranslate button is clicked void doTranslate() { translateInBackground(textInput.getText().toString()); } @Background // Executed in a background thread void translateInBackground(String textToTranslate) { String translatedText = callGoogleTranslate(textToTranslate); showResult(translatedText); } @UiThread // Executed in the ui thread void showResult(String translatedText) { result.setText(translatedText); result.startAnimation(fadeIn); }

AndroidAnnotations

Wednesday, May 23, 12

Wednesday, May 23, 12

</presentation>

murat@muratyener.comtwitter.com/yenermdevchronicles.com

blogs.eteration.com/blogs

Wednesday, May 23, 12

top related