Professional Documents
Culture Documents
Thread class :
Threads help in multi tasking
Threads can be taught as mini process running under a man process.
Threads enable at least appearance parallel execution.
Application of thread :
When android app is first started, runtime system will create a single main
thread, this main thread will take care of execution of all the components in
the android.
Handler Class :
For the purpose of multithreading, we shall use the handler class which
comes from the package android.os.Handler
Fro fig, we can see that each threas is handled by one one instance of a
Handler class.
Threads communicate with each other with the help of messeges.
This handler class helps to maintain snc-co ord b/w threads by allowing them
to run togather achieveing multithreading.
Handler Class :
Header class
Instance One ----------------------> Thread1--------Threads communicate with messeges.
Instance Two -------------------------> Thread 2-------
Intents
Android Intent is a messege that is passed between components such as
activities, content providers, broadcast receivers etc.
Intents are objects of android.content.intent type. your code can send them
to system defining the target components.
Intent Filters
Intents are used to signal the android system that some event has occured.
Intents often describe the action which should be performed and provide data
upon which such an action should be done.
A component can register itself via intent filter for specific action & data.
intent filter specifies the types of intents to which an activity, service,
broadcast receiver can respond by declaring the capabilities of a component.
android contents register intent filters either statically in the
AndroidManifest.xml or in case of a broadcast receiver also dynamically via
code. an intent filter is defined by its category, action and data filters. It can
also contail additional metadata.
A filter has fields that parallel the action data and ctegory fields of an intent
object. and implicit filter is tested against all the three areas.
Action :
A string that specifies the generic action to perform(such as view or pick). You
can specify your own actions for use by using intents within your app, but you
should usually use action constants defined by the intent class or other
framework classes. Here are some common actions for starting an activity.
Data : The URI (a uri object) that references the data to be acted upon and /or
the MIME(Multipurpose Internet Mail Extensions) type of data.
Category :
A string containing additional information about the kind of component that
should handle the intent. Android treats all the implicit intents passed to
startActivity() as if they contained at least one category
"android.intent.category.DEFAULT"
Extras :
Key-Value pairs that carry additional information required to ccomplish the
requested action. Just as some actions use perticular kinds of data like URLs,
& extras.
you can add extra data with various putExtra() methods, each accepting two
parameters : the key & the vcalue.
Yo can also create bundle object & insert the bundle in the intent with
putExtras();
Flags :
Flags defined in the intetnt class that function as metadata for the intent. The
flags may instruct the Android system how to launch an activity and how to
treat it after its launched.
Project 1
there shouldnt be any UI files in the newly made package All
UI files must be in default package.
Singleton Onject : Only one object will be created
throughout the project.
It will establish a connecton between array and data as the
database does!
We need only one object! whatoever.
AsyncTask
android enforces that with app not responding if the activity does not
interacts for 5 seconds. from this dialog, you can choose to stop app.
Android modifies the user interface via one thread, the so called UI
thread. If you perform a long running operation directly on UI thread,
i.e. UI will freeze untill the task is finished.
AsyncTask enables proper and easy use of the UI thread. Thiss class
allowes to perform background operations and publish results on the UI
thread without having having to manipulate threads and/or handlers.
Go to android developers/AsyncTask for more info.
Create a Class :
public class JsonAsync extends AsyncTask<params, progress,Result>
{
}
1 params(i.e. in parameters)
2 progress i.e progress
Methods :
onPreExecute() , invoke on UI thread before the task is executed.
doInBackground(params) invoked on background thread immeidately
after onPreExecute finishes. used to perform background computation.
onProcessUpdate(Progress) : invoked on UI thread after a call to
publishProgress(progress). timing of execution is undefined.Used to
display any kind of progress in UI while BackgroundComputation is still
executing.
onPostExecuted(Result) :
invoked on the UI thread after the background computation finishes.
Result of background computation is passed to this step as parameter.