1

How to pass data between activities? let’s say pass user id, city, and password to next activity and display it.

  • Intent in = new Intent();
    in.setAction("ACTION"); //this should match with other activity intent-filter
    in.setData(Uri.parse("uid","tech"));
    in.setData(Uri.parse("city","New Delhi"));
    in.setData(Uri.parse("pw","android"));
  • Intent in = new Intent
    in.setAction("ACTION"); //this should match with other activity intent-filter
    in.putExtra("uid","tech");
    in.putExtra("city","New Delhi");
    in.putExtra("pw","android");
  • Intent in = new Intent();
    in.setAction("ACTION"); //this should match with other activity intent-filter
    in.putExtra("tech");
    in.putExtra("New Delhi");
    in.putExtra("android");
  • Intent in = new Intent();
    in.setAction("ACTION"); //this should match with other activity intent-filter
    in.putExtra("uid");
    in.putExtra("city");
    in.putExtra("pw");

Answer: B Intent in = new Intent
in.setAction("ACTION"); //this should match with other activity intent-filter
in.putExtra("uid","tech");
in.putExtra("city","New Delhi");
in.putExtra("pw","android");
Description: Intent in = new Intent
in.setAction("ACTION"); //this should match with other activity intent-filter
in.putExtra("uid","tech");
in.putExtra("city","New Delhi");
in.putExtra("pw","android");

2

What is activity in android?

  • each widget in android is called as an activity.
  • Each screen in android, with which user interacts is called as an activity.
  • Every activity will have User Interface. An activity with out UI is impossible.
  • all are true

Answer: B Each screen in android, with which user interacts is called as an activity.
Description:

3

What is intent in android?

  • Intent is a message passing mechanism between 2 components of android.
  • Intent is used to start other components. Eg: you can start an activity or a service or you can send a broadcast using intents.
  • Intents can't be used with content providers.
  • all are true

Answer: D all are true
Description:

4

What are the different layouts available in android?

  • absolute layout
    frame layout
    relative layout
    linear layout
  • frame layout
    relative layout
    linear layout
    table layout
  • absolute layout
    frame layout
    relative layout
    linear layout
    table layout
  • none

Answer: C absolute layout
frame layout
relative layout
linear layout
table layout
Description:

5
What does below code do? Assume that c contains cursor row of an image
selected by user in gallery.

String path = c.getString(c.getColumnIndex(
MediaStore.MediaColumns.DATA));
File f = new File(path);
String abspath = f.getAbsolutePath();
Bitmap b = BitmapFactory.decodeFile(abspath);
  • It is fetching the path of that image, and then create bitmap using that path.
  • it is fetching the path of that image, then converting into absolute path, then creating bitmap with that absolute path using bitmapfactory class.
  • it is taking one image, and then fetching the path of that image, and getting absolute path of that image finally.
  • it is taking one image, and then fetching the path of that image, and getting absolute path of that image, then inserting that path into a table.

Answer: B it is fetching the path of that image, then converting into absolute path, then creating bitmap with that absolute path using bitmapfactory class.
Description: it is fetching the path of that image, then converting into absolute path, then creating bitmap with that absolute path using bitmapfactory class.

6

What is a context in android?

  • It is an interface to global information of an application.
  • contexts are generally used to create a new components or objects, like views. Contexts are also used to start an activity, or service or a receiver.
  • There are two types of contexts, activity context(this) and applicationcontext. You can obtain application context by getApplicationContext() method.
  • all are true

Answer: D all are true
Description:

7

What is an intent filter in android?

  • i. intent filter says what implicit "actions" a component can handle.
  • ii. intent filter says what explicit "actions" a component can handle.
  • iii. intent-filters are counterparts for intents. Android uses intent-filter before triggereing a component for an implicit intent.
  • i
  • i & ii
  • i & iii
  • all are true

Answer: C i & iii
Description:

8

Show one intent example code in android?

  • This is the code to start second screen by using explicit intent.
    Intent in = new Intent(this, SecondScreen.class);
    startActivity(in);
  • This is the code to start dialer screen by using implicit intent.
    Intent in = new Intent();
    in.setAction(Intent.ACTION_DIAL);
    startActivity(in);
  • option 1 is an example for implicit intent and option 2 is an example for explicit intent.
  • both option 1 and option 2 are correct.

Answer: D both option 1 and option 2 are correct.

Description:

9

Give one intent example in android?

  • This is the code to start second screen by using explicit intent.

    Intent in = new Intent(this, SecondScreen.class);
    startActivity(in);
  • This is the code to start dialer screen by using implicit intent.

    Intent in = new Intent();
    in.setAction(Intent.ACTION_DIAL);
    startActivity(in);
  • option 1 is an example for implicit intent and option 2 is an example for explicit intent.
  • both option 1 and option 2 are correct.

Answer: D both option 1 and option 2 are correct.
Description:

10

What is pending intent in android?

  • An intent that is stick with android system for future users is called as pending intent.
  • An intent which will be fired or triggered at future point of time by some one else (esp Alarm Manager or Notification Manager) on behalf of your application.
  • both are true
  • none

Answer: B An intent which will be fired or triggered at future point of time by some one else (esp Alarm Manager or Notification Manager) on behalf of your application.
Description:

11

What is the difference between viewgroup and layout?

  • i. viewgroup - is invisible container, and abstract class. Layouts are more concrete form of view groups.
  • ii. layout - is invisible container, and abstract class. Viewgroups are more concrete form of layouts.
  • iii. view groups derive from views, and layouts derive from view groups
  • iv. layouts, viewgropus both derive from view class only
  • i
  • ii
  • i & iii
  • ii & iv

Answer: C i & iii
Description: viewgroup - is invisible container, and abstract class. Layouts are more concrete form of view groups. view groups derive from views, and layouts derive from view groups.
Eg of layouts are 1.framelayout, 2.relative layout, 3.linear layout, etc..

12

how to handle key events in android? What is the key event flow?

  • Keyevents will flow from Activity to UI view. If Activity want, it can block any key event.
  • Keyevents will flow from Activity to UI view. But Activity will never block event flow, but if it is required UI View can block some event to stop Activity to handle it.
  • Keyevents will flow from Activity to UI view. But Activity will never block event flow, but UI View can't block event to stop Activity to handle it.
  • Keyevents will flow from Activity to UI view. But Activity will never block event flow, but if it is required UI View can block some event to stop Activity to handle it. Programmer also can block any Key event to stop UI View to handle it.

Answer: D Keyevents will flow from Activity to UI view. But Activity will never block event flow, but if it is required UI View can block some event to stop Activity to handle it. Programmer also can block any Key event to stop UI View to handle it.
Description: Key events will flow like this: Android system -> Activity -> Layout -> View -> programmer. First priority will be given programmer written logic, if programmer has written some thing to handle some key events it will be execute first. From there based on the return statement it will decide to flow back that key event to parent or not. eg: if programmer choose to block some key say KEYCODE_0, then for that key code he can say return true; which will block that event and will be destroyed in programmers function only.

13

android process priority: If my application is having one activity - in background state, service - in running state; then what is my process priority?

  • foreground process(1)
  • service process priority (3)
  • empty process(5)
  • visible process(2)

Answer: B service process priority (3)
Description: the process priority will be the maximum of components priority.

14

If my application is having one activity - in foreground state, and 2 other activities in - background states; then what is my process priority?

  • foreground process(1)
  • service process priority (3)
  • empty process(5)
  • visible process(2)

Answer: A foreground process(1)
Description: the process priority will be the maximum of components priority.

15

android process priority: If my application is having one activity - on which dialog is displayed; then what is my process priority?

  • service process priority (3)
  • empty process(5)
  • foreground process(1)
  • Visible process(2)

Answer: D Visible process(2)
Description: If dialog is displayed on top of activity, then all the UI events will be sent to Dialogue, so Activity is not in foreground state. But it will be visible to the user.so it is in visible priority (2).

16

android process priority: If my application is having one activity - in background state, service - in running foreground state; then what is my process priority?

  • service process priority (3)
  • foreground process(1)
  • Visible process(2)
  • empty process(5)

Answer: B foreground process(1)
Description: Generally services that are running will be having medium priority(3) , but we can request to run a service in foreground making it highest priority.

17
Android single thread UI model:
What is the problem with below program.
public class UiprogramActivity extends Activity {
/** Called when the activity is first created. */
Button b;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
new Thread(){
public void run(){
b.setText("Hacked from other thread..");
}//CalledFromWrongThreadException
}.start();
}
});
}
}
  • program will crash because worker thread is touch UI component directly.
  • program will crash because we are creating one more thread in button. all activities has to use only main thread.
  • program executes and sets the button 1 text as "hacked from other thread".
  • program gives compile time error.

Answer: A program will crash because worker thread is touch UI component directly.
Description: program will crash because worker thread is touch UI component directly.

18

How to rotate an image in ImageView?

  • Matrix m=new Matrix();
    imageView.setScaleType(ScaleType.MATRIX);
    m.postRotate((float) angle, pivX, pivY);
    imageView.setImageMatrix(matrix);
  • final RotateAnimation rotateAnim = new RotateAnimation(0.0f, degree,
    RotateAnimation.RELATIVE_TO_SELF, 0.5f,
    RotateAnimation.RELATIVE_TO_SELF, 0.5f);

    rotateAnim.setDuration(0);
    rotateAnim.setFillAfter(true);
    imgview.startAnimation(rotateAnim);
  • both are true
  • none

Answer: C both are true
Description:

19

How to take picture from camera in android?

  • //make a folder "pics" to store pics taken by the camera using this
    final String directory = Environment.getExternalStoragePublicDirectory (Environment.DIRECTORY_PICTURES) + "/pics/";
    File nd = new File(directory);
    nd.mkdirs();

    //what is the picture name?
    String file = directory+"myfile"+".jpg";
    File myFile = new File(file);
    try {
    myFile.createNewFile();
    } catch (IOException e) {}

    Uri myUri = Uri.fromFile(myFile);
    //prepare intent for starting camera
    Intent in = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    in.putExtra(MediaStore.EXTRA_OUTPUT, myUri);

    startActivityForResult(in, 1);
  • /make a folder "pics" to store pics taken by the camera using this
    final String directory = Environment.getExternalStoragePublicDirectory (Environment.DIRECTORY_PICTURES) + "/pics/";
    File nd = new File(directory);
    nd.mkdirs();

    //what is the picture name?
    String file = directory+"myfile"+".jpg";
    File myFile = new File(file);
    try {
    myFile.createNewFile();
    } catch (IOException e) {}

    Uri myUri = Uri.fromFile(myFile);

    //prepare intent for starting camera
    Intent in = new Intent(MediaStore.ACTION_CAMERA);
    in.putExtra(MediaStore.EXTRA_OUTPUT, myUri);

    startActivityForResult(in, 1);
  • both are true
  • none

Answer: A //make a folder "pics" to store pics taken by the camera using this
final String directory = Environment.getExternalStoragePublicDirectory (Environment.DIRECTORY_PICTURES) + "/pics/";
File nd = new File(directory);
nd.mkdirs();

//what is the picture name?
String file = directory+"myfile"+".jpg";
File myFile = new File(file);
try {
myFile.createNewFile();
} catch (IOException e) {}

Uri myUri = Uri.fromFile(myFile);
//prepare intent for starting camera
Intent in = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
in.putExtra(MediaStore.EXTRA_OUTPUT, myUri);

startActivityForResult(in, 1);
Description:

20

How to get current date in android?

  • Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdate = new SimpleDateFormat("dd-MMM-yyyy");
    String date = sdate.format(cal.getTime());
  • Calendar cal = Calendar.getInstance();
    int sec = c.get(Calendar.SECOND);
  • SimpleDateFormat dateFmt = new SimpleDateFormat("yyyyMMdd_HHmmss");
    String date = dateFmt.format(new Date());
  • both option 1 and option 3 are correct

Answer: D both option 1 and option 3 are correct
Description: