Software Development Exam  >  Software Development Videos  >  Android Application Development (Mobile App)  >  Android Application Development Tutorial - 50 - setResult for the Start Activity For Result

Android Application Development Tutorial - 50 - setResult for the Start Activity For Result Video Lecture | Android Application Development (Mobile App) - Software Development

FAQs on Android Application Development Tutorial - 50 - setResult for the Start Activity For Result Video Lecture - Android Application Development (Mobile App) - Software Development

1. What is the purpose of setResult in Android application development?
Ans. The setResult method is used to set the result that will be returned to the calling activity when the current activity finishes. It is typically used when the current activity is started for result using startActivityForResult.
2. How does startActivityForResult work in Android application development?
Ans. startActivityForResult is used to start a new activity and expect a result back from that activity. The called activity can set a result using setResult, which will be returned to the calling activity when the called activity finishes.
3. Can you provide an example of using setResult and startActivityForResult in Android application development?
Ans. Sure! Here's an example: In the calling activity: ``` Intent intent = new Intent(this, CalledActivity.class); startActivityForResult(intent, REQUEST_CODE); ``` In the called activity: ``` Intent resultIntent = new Intent(); resultIntent.putExtra("key", value); setResult(RESULT_OK, resultIntent); finish(); ``` In the calling activity (onActivityResult method): ``` @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE) { if (resultCode == RESULT_OK) { // Handle the result from the called activity String value = data.getStringExtra("key"); // Do something with the result } } } ```
4. What is the difference between startActivity and startActivityForResult in Android application development?
Ans. The startActivity method is used to start a new activity without expecting any result back. On the other hand, startActivityForResult is used to start a new activity and wait for a result to be returned from that activity.
5. Is it necessary to use startActivityForResult for result handling in Android application development?
Ans. No, it is not necessary to use startActivityForResult for result handling. It depends on the specific requirements of the application. If the calling activity does not need any result from the called activity, then startActivity can be used instead. However, if the calling activity expects a result, startActivityForResult should be used.
Related Searches

Sample Paper

,

Exam

,

Extra Questions

,

Free

,

ppt

,

Android Application Development Tutorial - 50 - setResult for the Start Activity For Result Video Lecture | Android Application Development (Mobile App) - Software Development

,

mock tests for examination

,

past year papers

,

Android Application Development Tutorial - 50 - setResult for the Start Activity For Result Video Lecture | Android Application Development (Mobile App) - Software Development

,

shortcuts and tricks

,

Important questions

,

study material

,

practice quizzes

,

Summary

,

video lectures

,

Android Application Development Tutorial - 50 - setResult for the Start Activity For Result Video Lecture | Android Application Development (Mobile App) - Software Development

,

Objective type Questions

,

MCQs

,

Previous Year Questions with Solutions

,

Viva Questions

,

pdf

,

Semester Notes

;