Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is use of start activity for result in Android? [duplicate]

Tags:

android

What is use of start activity for result in Android? Please give example and what is difference between startactivity and startactivityforresult?

like image 364
mohan Avatar asked May 03 '11 11:05

mohan


People also ask

What does start activity for result do?

By the help of android startActivityForResult() method, we can get result from another activity. By the help of android startActivityForResult() method, we can send information from one activity to another and vice-versa.

What can I use instead of start activity for results?

0 . It has deprecated startActivityForResult in favour of registerForActivityResult . It was one of the first fundamentals that any Android developer has learned, and the backbone of Android's way of communicating between two components.

What is start activity in Android?

Starting activities or services. To start an activity, use the method startActivity(intent) . This method is defined on the Context object which Activity extends. The following code demonstrates how you can start another activity via an intent.

What is return type of start activity for result android?

What are return types of startActivityForResult in android Options 1 RESULT OK 2 RESULT CANCEL 3 RESULT CRASH 4 A.


2 Answers

By calling startActivityForResult with Activity2, your current activity will be notified when the Activity2 is finished (back button pressed), and this way you can also get information from it.
This notification you can catch by overriding your activity's onActivityResult method.

This article about Android startActivity and startActivityForResult might be worth to look at.

like image 88
rekaszeru Avatar answered Sep 28 '22 00:09

rekaszeru


startActivityForResult() allows you to start activity and get some data back. Imagine that you have some file picker activity. You can start it and when user chooses the file, the result is given back to the original activity.

Also, it can be used if you simply want to ensure that the second activity has successfully done somethings.

The result code is obtained in onActivityResult method:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // Result OK.d.
        if (requestCode == resultCode) {
            // do something good
        }
    }
like image 26
Vladimir Ivanov Avatar answered Sep 28 '22 02:09

Vladimir Ivanov