0% found this document useful (0 votes)
60 views5 pages

Q (1) Type of State?: Paper Possible Questions

This document contains questions and answers related to core Android concepts. It discusses types of intents (explicit and implicit), shared preferences, text-to-speech, speech-to-text, and the basic building blocks of Android including activities, services, broadcast receivers, and content providers.

Uploaded by

WAqar Rao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views5 pages

Q (1) Type of State?: Paper Possible Questions

This document contains questions and answers related to core Android concepts. It discusses types of intents (explicit and implicit), shared preferences, text-to-speech, speech-to-text, and the basic building blocks of Android including activities, services, broadcast receivers, and content providers.

Uploaded by

WAqar Rao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Paper Possible Questions

Q(1) Type of State?

Q(2) Activity Life Cycle?


Q(3) What are some different log methods?

Q(4) What is Explicit Intent?


With explicit Intent other activity user created activity are called. For example we with the help
of explicit Intent we can not only launch other activity but also can send data in parameters. Vice versa
is also possible. The only difference is when getting result from other activity we have to call start
startActivityForResult() method having two parameters rather than one.

Simple Example (Sending Data from 1 side)

//This code is in our own method called with button


Intent intent = new Intent(this, Welcome.class);
intent.putExtra("Name", "Allam");
startActivity(intent)

//this is in onCreate of the second method


TextView textView = findViewById(R.id.textView);
Intent intent = getIntent();
String name = intent.getStringExtra("Name");
textView.setText(name);

Simple Example (Sending Data from 1 side and getting from other side)

Q(5) What is Implicit Intent?

Simple Example (All in user made button)

/*
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(6) SharedPreferences Code Level Example?

SharedPreferences pref = getPreferences(MODE_PRIVATE);


SharedPreferences.Editor edit = pref.edit();
//To put string
edit.putString("e", email);
edit.putString("p", password);
edit.commit();
//To Get
pref.getString("e", null);

For Multiple Activities


SharedPreferences prefs = getSharedPreferences("filename", MODE_PRIVATE);
SharedPreferences.Editor edit = prefs.edit();
edit.putInt("name", value);
edit.putString("name", value);
edit.commit();

Q(7)Text to Speech

Allows Android device to speak an audible message based on a text string.

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.

Q(8) Speech to Text

Speech-to-text: User talks; Android records, turns into a String.

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);

protected void onActivityResult(int requestCode,


int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
ArrayList<String> list = intent.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
String spokenText = list.get(0);
// ...
}

Q(9) Building Block of Android

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.

You might also like