RAMList.setOnClickListener(new View.OnClickListener() {
// ...
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// ...
}
});
This is not going to work as you expect. That onActivityResult
method will never be called.
onActivityResult
is a method of an Activity
, invoked by the Android runtime whenever that activity receives the result of another activity which it launched through startActivity(ForResult)
. You are trying to define it on a class solely implementing the View.OnClickListener
interface, which does not have an onActivityResult
method. It does not override any method of a superclass or interface, it's just a new method which has no special purpose at all.
You are passing that class instance to setOnClickListener
, which is only concerned with calling onClick
- as that is in the View.OnClickListener
interface. It doesn't know that there's an onActivityResult
method in that object, and it simply doesn't care.
If you want to get this working, you need to put that code in the onActivityResult
of your ListmenuActivity
. Since that class inherits Activity
, its onActivityResult
will be called for all activities launched by startActivity(ForResult)
. You'll need to differentiate between your two separate launches so you know what to do for the given result. That's why Android provides you with a requestCode
: give your different launches different requestCode
s and you'll be able to separate them when you receive their results in onActivityResult
.
Thus, your ListmenuActivity.onActivityResult
method should look like:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
// Handle result of CPUList
} else if (requestCode == 2) {
// Handle result of RAMList
}
super.onActivityResult(requestCode, resultCode, data);
}
You would launch your subactivities with startActivityForResult(CPUList, 1)
and startActivityForResult(RAMList, 2)
.
(Side note: it's very confusing if you name two different variables RAMList
- an EditText
and an Intent
- in the same scope.)