1

I am having main activity called OverallActivity. here I wrote a code to add menu, by selecting the menu I want to perform an action in another activity. Eg: main Activity: OverallActiviry menus: Action1 and Action2 If i click action1 it have to call the subActivity1 one. and If i press Action2,it have call the another activity(subActivity2), in that subActivity2 I want set the Listview to display the array(string() value returned by subActivity1. If anyone knows please revert me. Thanks in advance.

Thiru
  • 2,374
  • 7
  • 21
  • 29

4 Answers4

2

Override this method----

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.new_game:
   // start activty here
    return true;
case R.id.help:
  // start activty here
    return true;
default:
    return super.onOptionsItemSelected(item);
}

}

Tofeeq Ahmad
  • 11,935
  • 4
  • 61
  • 87
  • "java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.aspiresys.socialapp/com.aspiresys.socialapp.ActivityTwo}: java.lang.NullPointerException" It shows the error like this. Am I want to do any changes in manifest file – Thiru Jan 17 '12 at 08:45
  • check these link for this problem;;;http://stackoverflow.com/questions/4688277/java-lang-runtimeexception-unable-to-instantiate-activity-componentinfo and http://stackoverflow.com/questions/6443091/android-java-lang-runtimeexception-unable-to-instantiate-activity-componentinfo – Tofeeq Ahmad Jan 17 '12 at 09:23
2

At first I misunderstood your question, so now here's some correction:

To launch an activity, use Shashank Kadne's code in the code from TofeeqAhmad.

To pass data to subActivity2 you can add additional data to the intent that opens the Activity, in your case, an array of CharSequence items:

CharSequence[] sequences = ...;
intent.putExtra("resultsFromActivity1", sequences);

Then, in your activity's onCreate handler you could check whether the intent contains an extra named "operation" an what its value is:

CharSequence[] items = itent.getCharSequenceExtra("resultsFromActivity1");
if (items != null)
{
    // Display the items
}
Thorsten Dittmar
  • 55,956
  • 8
  • 91
  • 139
  • Thank you This Just same as my expectation. – Thiru Jan 17 '12 at 08:32
  • "java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.aspiresys.socialapp/com.aspiresys.socialapp.ActivityTwo}: java.lang.NullPointerException" It shows the error like this. Am I want to do any changes in manifest file – Thiru Jan 17 '12 at 08:44
  • I can not tell without the full stack trace and error message. I don't know which element is `null`. – Thorsten Dittmar Jan 17 '12 at 10:05
  • sorry for the inconvenience. Mistakenly i i had declared the Listview before the onCreat(). Thats what a problem here. – Thiru Jan 17 '12 at 10:22
1

http://developer.android.com/guide/topics/ui/menus.html#options-menu

Check part about responding to user action.

Seraphis
  • 1,026
  • 2
  • 14
  • 30
1

use Intents. Pass the class of the Activity to be called.

Add below lines in the listener to call subActivity1

Intent i = new Intent(OverallActiviry.this,subActivity1.class)
startActivity(i);
Shashank Kadne
  • 7,993
  • 6
  • 41
  • 54