1

I am developing an android application and I want to create a condition in an if statement in my first activity, say Activity A that checks if that activity (e.g. Activity A) has been triggered by an intent from another Activity (say Activity B) and then do something. So if I was to trigger Activity A from say Activity C for example the if statement in Activity A wouldn't execute the code inside the if statement. I haven't written any code for it because I don't know how to approach it. I've written only pseudo code to demonstrate what I want to do.

class Activity A {
 if(Activity A was triggered by an intent from Activity B)
 {
 do something
 }
}

Help would be most appreciated thank you.

Yury
21k8 gold badges62 silver badges87 bronze badges
asked Mar 12, 2011 at 11:59
1
  • Please accept an answer if one of them helped. Commented Jul 27, 2011 at 14:22

2 Answers 2

3

'putExtra()' in B and C and '.getExtras()' in A would be the easiest way. Have a look at steps 5 an 6 in

The notepad tutorial

(Plus you ought to check that the extras aren't null in Activity A to be on the safe side)

answered Mar 12, 2011 at 12:19
Sign up to request clarification or add additional context in comments.

Comments

0

You could also use startActivityForResult and then use onActivityResult to execute the code on return from whichever activity.

answered Mar 12, 2011 at 19:32

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.