0

I get an Android.Content.ActivityNotFoundException when attempting to start another Activity. I wasn't able to find any Information that tells me whether this is or is not possible.

This is how is start the Activity:

var intent = new Intent(this, typeof (ClassB));
intent.PutExtra("mac",mac);
intent.SetFlags(ActivityFlags.SingleTop);
StartActivityForResult(intent,_requestcodeControl);

This is the ClassB:

[Activity(Label = "ClassB", MainLauncher = false)]
public class ClassB : ClassA
{


    protected override void OnCreate(Bundle bundle)
    {
        Log.Debug(TAG, "OnCreate");
        base.OnCreate(bundle);
  .....

And this is the ClassA:

public abstract class ClassA : Activity
{

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

   .....

Can i define an Activity like that?

//edit: I adjusted my Manifest.xml so those 2 classes appear, because monodroid didn't add them.

<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="internalOnly" android:versionCode="1" android:versionName="0.0.1a">
  <application android:label="A" android:name="mono.android.app.Application" android:debuggable="true">
    <activity android:label="Classb" android:name="androidprotoype_mono.devices.ClassB" />
    <activity android:label="ClassA" android:name="androidprotoype_mono.devices.ClassA" />
   </application>
....

Now i dont get the exception anymore, but the app crashes before.

This is what the Log says:

E/AndroidRuntime(28005): FATAL EXCEPTION: main
E/AndroidRuntime(28005): java.lang.RuntimeException: Unable to instantiate activity  ComponentInfo{AndroidProtoype_Mono.AndroidProtoype_Mono/androidprotoype_mono.devices.ClassB}: java.lang.InstantiationException: androidprotoype_mono.devices.ClassB
E/AndroidRuntime(28005):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
E/AndroidRuntime(28005):        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
E/AndroidRuntime(28005):        at android.app.ActivityThread.access$1500(ActivityThread.java:117)
E/AndroidRuntime(28005):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
E/AndroidRuntime(28005):        at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(28005):        at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime(28005):        at android.app.ActivityThread.main(ActivityThread.java:3691)
E/AndroidRuntime(28005):        at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(28005):        at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(28005):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
E/AndroidRuntime(28005):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
E/AndroidRuntime(28005):        at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(28005): Caused by: java.lang.InstantiationException: androidprotoype_mono.devices.Samson64952
E/AndroidRuntime(28005):        at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime(28005):        at java.lang.Class.newInstance(Class.java:1409)
E/AndroidRuntime(28005):        at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
E/AndroidRuntime(28005):        at      android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
E/AndroidRuntime(28005):        ... 11 more

I retreat the Question. Made the derived Class abstract too. This was obviously the fault.

Martze
  • 921
  • 13
  • 32
  • 2
    Have you registered that activity properly in your AndroidManifest? *(if yes and the error persists, please post this manifest section)* –  Mar 29 '12 at 12:40
  • 2
    well, did you declare both activities in the manifest? – Th0rndike Mar 29 '12 at 12:41
  • you need to register your activity in manifest file http://stackoverflow.com/questions/4481903/how-to-register-a-new-activity-in-manifest-xml – vipin Mar 29 '12 at 12:43
  • I'm using Monodroid, so most of the manifest code is generated by these expressions: `[Activity(Label = "ClassB", MainLauncher = false)]` . I found the generated manifest file, and these classes don't even appear. I'll try now to manually add them. – Martze Mar 29 '12 at 12:51
  • @alextsc I posted the manifest section, and the problem persists. – Martze Mar 29 '12 at 13:12
  • Well, it's a different problem as it seems. I can't help you much here though, this seems to be a mono specific problem, while the other one was a more general one. I got no experience with c#/mono at all. –  Mar 29 '12 at 13:13

1 Answers1

0

Okay, got it working.

I somehow made the Activity i actually wanted to start abstract too. <- actual fault The Manifest file was not updated, because the classes were both abstract. Now only the non-abstract class is in the manifest, and it works.

The subfolders are no problem, it was all about that little abstract.

Martze
  • 921
  • 13
  • 32