with
by
Parthiban Loganathan
Different screen sizes
Different OS versions
... leading to frustrated Android developers
52% of US and 85% of the global mobile market + it's growing
Growing ecosystem - Android Wear, Google Glass
You will need:
Setup can sometimes be complicated and often machine specific.
Come to Cookies & Code for help.
Activities (stuff you can see)
Services (happen in background)
Broadcast receivers (react to system broadcasted messages)
Content providers (accessing data)
We will only use Activities today
Doesn't matter at this stage.
Pick your favorite:
* result of banging head on keyboard
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="10px"
android:paddingLeft="10px"
<Button
android:id="@+id/sample_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:background="#50AD21"
android:text="Click me!" />
</LinearLayout>
A LinearLayout with a Button
Plain old Java + Android specific methods via interfaces to start new activities, access SharedPreferences, etc.
// Get an object that represents the button view declared in the XML
mButton = (Button) findViewById(R.id.sample_button);
// Set an onClickListener to react to it
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Do stuff here on click
}
});
* default project structure varies with different versions of Android Studio (it's still in beta)
I went crazy and added 2 libraries and a bunch of other stuff to let us tweet pictures.
But seriously, the concepts to know are:
Remember to handle edge cases - there are a ton of them. Eg - storing state on screen rotation, exiting and resuming app, starting duplicate services by accident, etc.
...also applies to some stuff I didn't cover like Fragments
Don't use getBaseContext(). Avoid using activity context to prevent memory leaks. Be wary of passing the context around since it won't be garbage collected.
Try getApplicationContext() when possible.
RxJava by Netflix
Flow
Mortar
Dagger
ButterKnife
Retrofit
github.com/parthibanloganathan/android-tutorial
adicu.com/resources > Android
parthi (at) adicu.com
@parthiban_logan
OR
come to Cookies and Code on Wednesdays at 10 PM in
Satow Room, Lerner 5th Floor