tags:

views:

100

answers:

1
private Button.OnClickListener goFirstPage = new Button.OnClickListener() {

public void onClick(View v) { try {

Intent i = new Intent(v.getContext(), quizMath.class); startActivityForResult(i, 0);

} catch (Exception e) { e.printStackTrace(); // TODO: handle exception }

} }; hi, this is my code, but the problem is that i want to call a function from class quizmath.So is it possible or not?. can we pass integer or string from startActivityForResult?

+1  A: 

Hey,

Yes it's possible. You'll find documentation for Intent here http://developer.android.com/reference/android/content/Intent.html

Before you start the activity you can use the putExtra function on your intent.

i.putExtra( "yourapp.function_to_call", "subtract" );

This is going to be passed to your activity and you can get out the information with the Intent.getStringExtra function. In your activity you can then do something like this.

Intent i = this.getIntent();
String fname = i.getStringExtra( "yourapp.function_to_call" );
if( fname.equals("add") )
    // ...
svens
public void onClick(View v) { try { login_profile.makeNewProfile(); Intent ii = new Intent(v.getContext(), login_profile.class); startActivityForResult(ii,0); ii.putExtra(com.example.android.login_profile.makeNewProfile(), "bibek"); }i did like this but the problem is how can i get the value "bibek" from function makeNewProfile?
RBADS
Or can i pass button id from view? i have 4 buttons and each button has same function but i want to know which button is calling a function?
RBADS
1. You have to call putExtra before startActivity. 2. Look at the documentation for Intent. The first parameter has to be a String. Does makeNewProfile() return a String? 3. Have a look at the View documentation (http://developer.android.com/reference/android/view/View.html). You could fore exaple use getId() to identify the calling view.
svens