I have a non-Activity class (let’s call it “NonActivity”) that needs to post a message and get user feedback. I have a message activity (MsgActivity) class to do this. But only Activity classes can call startActivityForResult() so I made an inner helper class in NoActivity:
// just to provide an Activity to launch MsgActivity
class ActivityMsgClass extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent iMA = new Intent(this, MsgActivity.class);
iMA.putExtra("MsgText", mParams[0]);
...blah blah ...
iMA.putExtra("ButtonCode", iBtns);
startActivityForResult(iMA,3);
}
}
My Activity class is declared in the Manifest thusly:
<activity android:name="ActivityMsgClass"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:launchMode="singleInstance"></activity>
But when I try to invoke it . . .
Intent i = new Intent(ctx, ActivityMsgClass.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(i);
… I get an ActivityNotFound exception. I’ve also tried it without the FLAG_ACTIVITY_NEW_TASK, and I’ve also tried qualifying the name in the manifest, e.g.,
<activity android:name=".NoActivity.ActivityMsgClass"
. . . to no avail. What am I doing wrong?
Thanks in advance.
The technical solution is to specify the fully qualified activity path in the manifest.
The actual solution is to avoid doing this. Let activity be a public class, and not an inner class, this is just not good practice.