154 lines
4.5 KiB
Plaintext
154 lines
4.5 KiB
Plaintext
Android
|
|
|
|
February 25, 2016
|
|
Brian Buller
|
|
Buller Codeworks, LLC
|
|
|
|
* Generally
|
|
|
|
Native Android is Java...
|
|
|
|
* Generally
|
|
|
|
Native Android is Java...
|
|
|
|
but I'm not talking about that
|
|
|
|
* Android Manifest
|
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
package="com.example.application"
|
|
android:versionCode="3"
|
|
android:versionName="1.2" >
|
|
<uses-permission android:name="android.permission.INTERNET" />
|
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
|
<application android:label="@string/app_name"
|
|
android:icon="@drawable/ic_launcher"
|
|
android:theme="@android:style/Theme.Holo.Light" >
|
|
<activity android:name=".FeedListActivity"
|
|
android:label="@string/app_name"
|
|
android:launchMode="singleInstance">
|
|
<intent-filter>
|
|
<action android:name="android.intent.action.MAIN" />
|
|
<category android:name="android.intent.category.LAUNCHER" />
|
|
</intent-filter>
|
|
</activity>
|
|
...
|
|
</application>
|
|
</manifest>
|
|
|
|
* Permissions
|
|
- Sandboxed Applications
|
|
- Normal Permissions
|
|
The permission must be declared, but the system automatically grants access
|
|
- Dangerous Permissions
|
|
The user must grant permission
|
|
- Changes in Android 6
|
|
- List of permissions and severity at [[http://developer.android.com/guide/topics/security/permissions.html]]
|
|
|
|
* Permissions Example
|
|
- Declared in manifest
|
|
|
|
<uses-permission android:name="android.permission.INTERNET" />
|
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
|
|
|
- Request at run time
|
|
|
|
ActivityCompat.requestPermissions(thisActivity,
|
|
new String[]{Manifest.permission.READ_CONTACTS},
|
|
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
|
|
|
|
* Intents
|
|
- Declare in manifest
|
|
|
|
<intent-filter>
|
|
<action android:name="android.intent.action.MAIN" />
|
|
<category android:name="android.intent.category.LAUNCHER" />
|
|
</intent-filter>
|
|
|
|
- Call in code
|
|
|
|
Intent shareIntent = new Intent();
|
|
shareIntent.setAction(Intent.ACTION_SEND);
|
|
shareIntent.putExtra(Intent.EXTRA_TEXT, alert_message);
|
|
shareIntent.setType("text/plain");
|
|
startActivity(shareIntent);
|
|
|
|
* Activities
|
|
Main Activity (icon in launcher)
|
|
|
|
<activity android:name=".FeedListActivity"
|
|
android:label="@string/app_name"
|
|
android:launchMode="singleInstance">
|
|
<intent-filter>
|
|
<action android:name="android.intent.action.MAIN" />
|
|
<category android:name="android.intent.category.LAUNCHER" />
|
|
</intent-filter>
|
|
</activity>
|
|
|
|
Other Activities
|
|
|
|
<activity android:name=".FeedDetailActivity"
|
|
android:label="@string/app_name"
|
|
android:launchMode="singleInstance">
|
|
</activity>
|
|
|
|
|
|
* Application Lifecycle
|
|
General Lifecycle
|
|
|
|
- Resumed
|
|
|
|
The activity has the user focus (aka - Running)
|
|
|
|
- Paused
|
|
|
|
Another activity is in the foreground, but this one is still visisble.
|
|
A Paused activity is fully alive but can be killed by the system in extremely
|
|
low-memory situations.
|
|
|
|
- Stopped
|
|
|
|
The activity is completely obscured by another activity. The activity is still alive,
|
|
but no longer visible and can be killed if memory is needed elsewhere.
|
|
|
|
* Application Lifecycle
|
|
Functions
|
|
- onCreate - The activity is being created
|
|
- onStart - The activity is about to become visible
|
|
- onResume - The activity has become visible
|
|
- onPause - Another activity is taking focus
|
|
- onStop - The activity is no longer visible
|
|
- onDestroy - The activity is about to be destroyed
|
|
|
|
Those are all overrides and you *must* hit the overridden function before doing any work in them.
|
|
|
|
* Layout Files
|
|
|
|
<LinearLayout
|
|
android:id="@+id/layout_id"
|
|
android:layout_width="match_parent"
|
|
android:layout_height="match_parent"
|
|
android:orientation="vertical">
|
|
<TextView android:id="@+id/layout_text"
|
|
android:layout_width="match_parent"
|
|
android:layout_height="wrap_content"
|
|
android:text="Text"
|
|
android:textSize="25dip" />
|
|
<Button android:id="@+id/layout_button"
|
|
android:layout_width="wrap_content"
|
|
android:layout_height="wrap_content"
|
|
android:text="Button Text" />
|
|
<LinearLayout android:id="@+id/list_wrapper"
|
|
android:layout_width="match_parent"
|
|
android:layout_height="match_parent"
|
|
android:orientation="vertical">
|
|
<ListView android:id="@+id/list_view"
|
|
android:listSelector="#00000000"
|
|
android:layout_width="match_parent"
|
|
android:layout_height="wrap_content" />
|
|
</LinearLayout>
|
|
</LinearLayout>
|
|
|
|
* Notes
|
|
The slides are available on [[http://gogs.bullercodeworks.com/brian/talks/2016/02/android.slide]]
|