Articles

Affichage des articles associés au libellé StartActivityForResult

Tuto Android: utilisation de startActivityForResult() au niveau de l'Intent

Image
A l'aide de la méthode Android startActivityForResult (), nous pouvons obtenir des résultats d'une autre activité. A l'aide de la méthode Android startActivityForResult (), nous pouvons envoyer des informations d'une activité à l'autre et vice-versa. La méthode startActivityForResult(), nécessite un résultat de la deuxième activité (l’activité invoquée). Dans ce cas, nous devons substituer la méthode onActivityResult() qui est appelée automatiquement lorsque la deuxième activité rendra le résultat. Dans notre exemple nous voulons passer le l’activité principale à l’activité secondaire après avoir cliqué sur le bouton. Il faut utiliser startActivityForResult().La première activité contient un TextView et un bouton. La seconde activité contient un EditText et un bouton. Lorsque l’utilisateur tape quelque chose dans l’EditText et clique sur le bouton soumettre l’activité principale doit s’afficher et le TextView doit afficher le contenu que l’utilisat

Advanced use of Intents: Android StartActivityForResult Example

Image
In the previous tutorial   Android Tutorial : Using Intent to move from one activity to another and sending data via putExtra   , we saw the use of intent to move from one activity to another, today we will see how to  receive a result from the  second  activity.  The intent was instructed to call the second activity and through the startActivity method to display it.  Imagine that our secondary activit y has a result to return to the first activity.  Our objective is to   start a second activity that returns result “data” to first activity. At first c reate a new Android Application. File  >>  New  >>  Android Application Enter Project name:  StartActivity Keep other default selections, go  Next   until you reach  Finish In your layout folder you must have two Layouts XML files. The first XML file "activity_main.xml" must contain a Button and the second XML file "second_activity.xml" must contain an EditText and a Button. res/