Introduction to Android development
App structure
build.gradle
- Contains dependencies fetched by Gradle ("package.json like")
- App configuration:
applicationId "test.florian.androidtestapp"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
AndroidManifest.xml
-
Permissions
-
Application
-
Activities
Activity
part of the application's visual user interface
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Main activity:
public class LoginActivity extends AppCompatActivity {
//...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(...); // Create interface
}
}
~ Angular/Ionic controller, React Native smart component/page
Layouts
defines the visual structure for a user interface, such as the UI for an activity or app widget
- XML based layouts
- "Flexbox" :
- R.id.* to access elements in the Java classes
- Designer in Android Studio
Fragments
piece of an application's user interface or behavior that can be placed in an Activity
- Can be designed with the Designer too
- Using the same XML based layouts
- Lifecycle tied to the activity using it
Intent
- Launch other activities of the app
- Launch another app
- Intent can have parameters ("extra")
startActivity(new Intent(view.getContext(), TabActivity.class));
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Debugging
adb logcat/pidcat/Android monitor tab in Android Studio
First step: read the logs
Debugger integrated to the IDE
Keyboard
<activity android:windowSoftInputMode="stateVisible|adjustResize" ... >
adjustPan
adjustResize
Read media files
MediaStore
final Cursor cursor = context.getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, null, null, null);
https://github.com/bamlab/rn-camera-roll/blob/master/android/src/main/java/fr/bamlab/rncameraroll/CameraImagesManager.java
HTTP requests
AsyncHttpClient looks nice
AsyncHttpClient asyncHttpClient = new DefaultAsyncHttpClient();
asyncHttpClient.prepareGet("http://www.example.com/").execute(
new AsyncCompletionHandler<Response>(){
public Response onCompleted(Response response) throws Exception{
// Do something with the Response
return response;
}
public void onThrowable(Throwable t){
// Something wrong happened.
}
});
https://github.com/bamlab/chooz-it-app/blob/chooz-integration/android/app/src/main/java/fr/bamlab/fileuploadandroid/FileUploader.java
Proguard
-
Beware of shrinking
-
Shrink/obfuscate code
when making method to interface with Javascript
Thanks :)
Native Android Development
By Florian Rival