Q (1) Type of State?: Paper Possible Questions
Q (1) Type of State?: Paper Possible Questions
Simple Example (Sending Data from 1 side and getting from other side)
/*
Uri number = Uri.parse("tel:03312919573");
Intent callInt = new Intent(Intent.ACTION_DIAL, number);
startActivity(callInt);
//Dials number
*/
/*
Uri webpage = Uri.parse("https://stackoverflow.com/questions/18395379/implicit-intent-for-camera-
capture-in-android");
Intent web = new Intent(Intent.ACTION_VIEW, webpage);
startActivity(web);
*/
/*
Launching Camera
Intent callInt = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivity(callInt);
*/
Q(7)Text to Speech
TextToSpeech tts;
Boolean ttsReady = false;
//onCreate
tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
ttsReady = true;
}
});
//onClick
public void onClick(View view)
{
if(ttsReady)
tts.speak("Usama!",TextToSpeech.QUEUE_FLUSH, null);
}//onClick
QUEUE_ADD
Queue mode where the new entry is added at the end of the playback queue.
QUEUE_FLUSH
Queue mode where all entries in the playback queue (media to be played and text to be
synthesized) are dropped and replaced by the new entry. Queues are flushed with respect to a given
calling app. Entries in the queue from other callees are not discarded.
Code:
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
// prompt text is shown on screen to tell user what to say
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "text");
startActivityForResult(intent, requestCode);
1. Activities
Activity is just a class. A class which extends from Activity, for the purpose of GUI. Example:
Like if are using Music Player, all the song content which shows in list, it is GUI and it is shown
on Activity/Fragment.
2.Service
It is used when we have to perform long running operation in background / or without blocking
UI. Like if we have to upload large file we cannot block ui for 1min or may be more so in that case
we have to use Service. Example: Class ExampleService extends Service.We have to declare
Service in Manifest file.
3.BroadCast Receiver
This is also a java class but it extends from BroadCast Receiver . Example : class
ExampleBroadCast extends BroadCastReceiver {} .
4.Content Provider
Content provider provide data from one application to others on request, and these requests
are handled by the methods of the ContentResolver class. The data may be stored the db or file.