Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass event data between activities?
    text
    copied!<p>I wanna pass an event data from Activity B to Activity A.</p> <p>Activity A looks like this : </p> <pre><code>public class ActivityDemo extends Activity { private Intent mIntent; private Context mContext; private TextView mText; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.demo_activity); mContext = getApplicationContext(); Button button = (Button)findViewById(R.id.qbutton); if (button != null) { button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mIntent = new Intent(mContext, DualActivity.class); if (mIntent != null) { startActivity(mIntent); } } }); } mText = (TextView)findViewById(R.id.qText); } ... protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { mText.setText(data.getStringExtra("TextOut")); } } </code></pre> <p>Activity B is like this :</p> <pre><code>public class DualActivity extends Activity implements QFragment.OnDataPassToActivity { private Context mContext; private Intent mIntent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = getApplicationContext(); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(SUIRes.layout(getApplicationContext(), "dual_default_activity")); mIntent = getIntent(); } public void onDataPassToActivity(String string) { if(mIntent != null) { mIntent.putExtra("TextOut", string); } //Toast.makeText(getApplicationContext(), string, Toast.LENGTH_SHORT).show(); } } </code></pre> <p>Activity B is originally called by Activity A, and onDataPassToActivity() is a callback function which is called by another class. I want to send string data to Activity A when onDataPassToActivity() function is called. I checked commented Toast works fine while callback is being called, but cannot send intent to Activity A.</p> <p>Is there any other solution to this problem?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload