Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Unable to find explicit activity class - how to resolve

JonathanTJonathanT Member ✭✭
edited November 2019 in Xamarin.Android

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 <receiver

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

Best Answer

Answers

  • JonathanTJonathanT Member ✭✭
    edited November 2019
     <?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>
    




    `

  • JonathanTJonathanT Member ✭✭
    <?xml version="1.0" encoding="utf-8"?>





















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

  • JonathanTJonathanT Member ✭✭

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

  • LeonLuLeonLu Member, Xamarin Team Xamurai
    edited November 2019

    @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.

  • JonathanTJonathanT Member ✭✭


    Error message is > Unable to find explicit activity class {com.Premier.WPD/md5eda0afe6bcda3bda3f63069927d2a34c.AppData_Droid}<
    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?
    AppData_Droid is the name of the main class in this cs file:
    public class AppData_Droid : Activity, EMDKManager.IEMDKListener

    Thank you.

  • JonathanTJonathanT Member ✭✭

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

Sign In or Register to comment.