![]() |
![]() |
![]() |
![]() |
<uses-permission
android:name="android.permission.INTERNET"/>
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<activity
android:name="DownloadActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/%gt;
</intent-filter>
</activity>
<service android:name="DownloadBoundServiceSync"
android:process=":my_process/>
<service android:name="DownloadBoundServiceASync"
android:process=":my_process/>
</activity>
DownloadActivity
class that inherits
from Activity
and uses the XML layout containing a
TextView
object that prompts for the URL of the bitmap
file and stores the entered URL in an EditText
object.
Button
objects with the labels "Run
Sync AIDL", "Run Async AIDL", and "Reset Image" to run the
corresponding hook methods that use the URL provided by the user to
start the appropriate Bound Service that downloads the designated
bitmap file via the following two Android concurrency and AIDL models:
DownloadActivity
spawns a Thread
(or an
AsyncTask
), binds to a
DownloadBoundServiceSync
process, and uses a synchronous
twoway AIDL method invocation to request that this service (1)
download a designated bitmap file, (2) store it in the Android file
system, and (3) use the return value from the synchronous AIDL method
invocation to return the filename back to thread, which opens the file
and causes the bitmap to be displayed on the screen. You'll need a
single *.aidl file with a single AIDL interface for this model.
DownloadActivity
binds to a
DownloadBoundServiceAsync
process and uses an
asynchronous oneway AIDL method invocation to request that this
service (1) download a designated bitmap file, (2) store it in the
Android file system, and use another oneway AIDL interface passed as a
parameter to the original oneway AIDL method invocation to return the
filename back to DownloadActivity
as a callback, which
opens the file and causes the bitmap to be displayed on the screen.
You'll need a two *.aidl files with two AIDL interfaces (one for the
callback interface and one for the callback registration interface)
for this model.
DownloadBoundServiceSync
and
DownloadBoundServiceAsync
components must run in
different processes than the DownloadActivity
component.
Button
objects that initiate the downloading of
the bitmap file must be connected to the corresponding
DownloadActivity.run*()
methods via the appropriate
android:onClick="..."
attributes.
TextView
,
EditText
, or Button
objects into your
DownloadActivity
class.
interface DownloadCall
{
String downloadImage (in Uri uri);
}
interface DownloadCallback {
oneway void sendPath (in String imageFilePath);
}
interface DownloadRequest {
oneway void downloadImage (in Uri uri, in DownloadCallback callback);
}
There's a great deal of useful information on Android AIDL and Binder available on the web and in your textbook, but make sure not to blindly copy and paste it..
Back to CS 282 home page.