Often you need to check something and/or take action once a menu closes. The examples on this topic seem sparse.
One way to achieve this is to use methods of the Activity class:
startActivityForResult(Intent, int)
and a corresponding: 
onActivityResult(int requestCode, int resultCode, Intent data)
The requestCode is an int you define to correlate between activities...
Here's an example:
@Override
 public boolean onOptionsItemSelected(MenuItem item) {
  switch (item.getItemId()) {
  case R.id.preferences:
   // Launch Preference activity
   Intent i = new Intent(HelloPreferences.this, Preferences.class);
   startActivityForResult(i,REQUEST_CODE_PREFERENCE);
   break;
  }
  return true;
 }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     super.onActivityResult(requestCode, resultCode, data);
     // do something here when menu closes
    }
Subscribe to:
Post Comments (Atom)
 
No comments:
Post a Comment