locked
Unable to find explicit activity class - how to resolve RRS feed

  • Question

  • User377198 posted

    Hi. I am trying to get an app to start on boot up. On boot up the app runs just enough to create an error message before crashing. The error message is

    Unable to find explicit activity class {com.Premier.WPD/md5eda0afe6bcda3bda3f63069927d2a34c.StartMyServiceAtBootReceiver}; have you declared this activity in your AndroidManifest.xml?<

    The code snippet from the activity is:

      namespace Database3
     {  
    
      [Activity(Label = "WPD", Theme = "@style/AppTheme", MainLauncher = true, ScreenOrientation = ScreenOrientation.Portrait)]  
       //< this line denotes this is the opening activity.
    
    
       [BroadcastReceiver(Enabled = true)]
        [IntentFilter(new[] { Intent.ActionBootCompleted })]
       public class StartMyServiceAtBootReceiver : BroadcastReceiver
       {
        #region implemented abstract members of BroadcastReceiver
        public override void OnReceive(Context context, Intent intent)
        {
            try
            {
                if (intent.Action == Intent.ActionBootCompleted)
                {
                    Toast.MakeText(context, "Received intent!", ToastLength.Long).Show();
    
                    Intent serviceStart = new Intent(context, typeof(StartMyServiceAtBootReceiver));
                    serviceStart.AddFlags(ActivityFlags.NewTask);
                    context.StartActivity(serviceStart);
    
                }
    
            }
            catch (Exception ex)
            {
                Toast.MakeText(context, ex.Message, ToastLength.Long).Show();
    
                string path2 = "/storage/emulated/0/Download/";
                string filename2 = path2 + "Error on boot log17.txt";      //          Path.Combine(path, gstrLocationFilename);
                using (var streamWriter = new StreamWriter(filename2, false))   //true = append
                {
                    streamWriter.Write(ex.Message);
                    streamWriter.Close();
                }
              }
           }
          #endregion
    
       }
    
    
    public class AppData_Droid : Activity, EMDKManager.IEMDKListener
     {
        Button locationButton;
        Button typeButton;
        Button serialButton;
        TextView hintsTextView;
        EditText locationEditText;
        EditText typeEditText;
        EditText serialEditText;
        TextView lastSerialScanTextView;
       etc. for the rest of the app which works fine.
    

    The AndroidManifest snippet is

        <?xml version="1.0" encoding="utf-8"?>
         <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" 
        package="com.Premier.WPD" android:installLocation="auto">
    <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="27" />
    <uses-permission android:name="android.permission.NFC" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-feature android:name="android.hardware.location" android:required="false" />
    <uses-feature android:name="android.hardware.location.gps" android:required="false" />
    <uses-feature android:name="android.hardware.location.network" android:required="false" />
    <uses-permission android:name="com.symbol.emdk.permission.EMDK" />
    
         <activity android:name=".StartMyServiceAtBootReceiver"/>
        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
        <service android:name=".StartMyServiceAtBootReceiver" android:label="WPD Boot">
         <intent-filter>
        <action android:name=".StartMyServiceAtBootReceiver" />
         </intent-filter>
       </service>
    
      <receiver 
          android:name=".StartMyServiceAtBootReceiver"     
          android:label="StartMyServiceAtBootReceiver">
        <intent-filter >
          <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>   
       </receiver>
    
    
       <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="WPD" android:roundIcon="@mipmap/ic_launcher" 
         android:supportsRtl="true" android:theme="@style/AppTheme">
         <uses-library android:name="com.symbol.emdk" />
    </application>
      </manifest>
    

    Particularly the 'paragraphs' starting and

    What must I do to declare this activity in my AndroidManifest.xml? Thank you.

    Wednesday, November 13, 2019 11:35 AM

Answers

  • User379860 posted

    @JonathanT You can create a Activity and make a test, like following code.

        [BroadcastReceiver(Enabled = true)]
        [IntentFilter(new[] { Intent.ActionBootCompleted })]
        public class BootBroadcastReceiver : BroadcastReceiver
        {
        public override void OnReceive(Context context, Intent intent)
        {
    
                Toast.MakeText(context, "Received intent!", ToastLength.Long).Show();
    
                //Put a Activity1 in Intent, You put the StartMyServiceAtBootReceiver is not correctly.
                Intent serviceStart = new Intent(context, typeof(Activity1));
                serviceStart.AddFlags(ActivityFlags.NewTask);
                context.StartActivity(serviceStart);
    
    
          }
       }
    

    This is code for Activity1, I notice your AppData_Droid not add the [Activity(Label = "Activity1")] attribute.

        [Activity(Label = "Activity1")]
    public class Activity1 : Activity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.layout1);
            // Create your application here
        }
    }
    

    layout1.xml

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
    <TextView
        android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:textSize="@dimen/abc_action_bar_content_inset_material"
         android:text="push up a activity"
       />
      </LinearLayout>
    

    I upload my demo. you can test it.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, November 14, 2019 7:41 AM

All replies

  • User377198 posted
     <?xml version="1.0" encoding="utf-8"?>
     <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" 
       android:versionName="1.0" package="com.Premier.WPD" android:installLocation="auto">
    <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="27" />
    
       <activity android:name=".StartMyServiceAtBootReceiver"/>
      <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
      <service android:name=".StartMyServiceAtBootReceiver" android:label="WPD Boot">
      <intent-filter>
         <action android:name=".StartMyServiceAtBootReceiver" />
      </intent-filter>
      </service>
    
     <receiver 
      android:name=".StartMyServiceAtBootReceiver"     
       android:label="StartMyServiceAtBootReceiver">
    <intent-filter >
          <action android:name="android.intent.action.BOOT_COMPLETED" />
      </intent-filter>   
    </receiver>
    

    `

    Wednesday, November 13, 2019 11:38 AM
  • User377198 posted

    android:label="StartMyServiceAtBootReceiver">

      <uses-library android:name="com.symbol.emdk" />
    </application>
    

    Wednesday, November 13, 2019 11:38 AM
  • User377198 posted

    Apologies for the gaps - this page won't accept my AndroidManifest. I'll convert it to an image.

    Wednesday, November 13, 2019 11:40 AM
  • User379860 posted

    @JonathanT

    Your code:

                Intent serviceStart = new Intent(context, typeof(StartMyServiceAtBootReceiver));
                serviceStart.AddFlags(ActivityFlags.NewTask);
                context.StartActivity(serviceStart);
    

    StartMyServiceAtBootReceiver it seems a BroadcastReceiver , not a Activity

    Please change the StartMyServiceAtBootReceiver to set a Activity, then make a test.

    Wednesday, November 13, 2019 12:43 PM
  • User377198 posted

    Error message is > Unable to find explicit activity class {com.Premier.WPD/md5eda0afe6bcda3bda3f63069927d2a34c.AppDataDroid}< What do I have to do to find the explicit activity class? I've tried a lot of permutations of with or without com.Premier etc. Does the public class StartMyServiceAtBootReceiver : BroadcastReceiver have to be in a different cs file? AppDataDroid is the name of the main class in this cs file: public class AppData_Droid : Activity, EMDKManager.IEMDKListener

    Thank you.

    Wednesday, November 13, 2019 1:49 PM
  • User379860 posted

    @JonathanT You can create a Activity and make a test, like following code.

        [BroadcastReceiver(Enabled = true)]
        [IntentFilter(new[] { Intent.ActionBootCompleted })]
        public class BootBroadcastReceiver : BroadcastReceiver
        {
        public override void OnReceive(Context context, Intent intent)
        {
    
                Toast.MakeText(context, "Received intent!", ToastLength.Long).Show();
    
                //Put a Activity1 in Intent, You put the StartMyServiceAtBootReceiver is not correctly.
                Intent serviceStart = new Intent(context, typeof(Activity1));
                serviceStart.AddFlags(ActivityFlags.NewTask);
                context.StartActivity(serviceStart);
    
    
          }
       }
    

    This is code for Activity1, I notice your AppData_Droid not add the [Activity(Label = "Activity1")] attribute.

        [Activity(Label = "Activity1")]
    public class Activity1 : Activity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.layout1);
            // Create your application here
        }
    }
    

    layout1.xml

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
    <TextView
        android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:textSize="@dimen/abc_action_bar_content_inset_material"
         android:text="push up a activity"
       />
      </LinearLayout>
    

    I upload my demo. you can test it.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, November 14, 2019 7:41 AM
  • User377198 posted

    Thank you LeonLu - I merged your MainActivity.cs into mine and it works great. 5 stars!

    Thursday, November 14, 2019 11:02 AM