See two application icons on target device

AlvinKwekAlvinKwek USMember ✭✭
edited November 2013 in Xamarin.Android

I have a strange problem describe below.

I wrote an Android application, connect my android device to my computer and run the application from Xamarin.
When the installation is completed, I see two application icons on my target device.
When I click on one of the icon, the problem crashed. When I click on the other one, the programs runs smoothly.

I provide a screen shot for your easy understanding.
Can someone me tell me where goes wrong?

Posts

  • mhutchmhutch USMember, Xamarin Team Xamurai

    Did you change your app ID? Are there any errors in the device log when the app crashes?

  • AlvinKwekAlvinKwek USMember ✭✭
    edited November 2013

    How can check if I have change the app ID?
    Below is the application output copied from Xamarin Studio

    [monodroid-gc] GREF GC Threshold: 46800
    [AndroidRuntime] Shutting down VM
    [AndroidRuntime] FATAL EXCEPTION: main
    [AndroidRuntime] java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{DFRS_AlHikmah.DFRS_AlHikmah/DFRS_AlHikmah.DFRS_AlHikmah.MainActivity}: java.lang.ClassNotFoundException: DFRS_AlHikmah.DFRS_AlHikmah.MainActivity
    [AndroidRuntime] at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2024)
    [AndroidRuntime] at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
    [AndroidRuntime] at android.app.ActivityThread.access$600(ActivityThread.java:140)
    [AndroidRuntime] at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
    [AndroidRuntime] at android.os.Handler.dispatchMessage(Handler.java:99)
    [AndroidRuntime] at android.os.Looper.loop(Looper.java:137)
    [AndroidRuntime] at android.app.ActivityThread.main(ActivityThread.java:4898)
    [AndroidRuntime] at java.lang.reflect.Method.invokeNative(Native Method)
    [AndroidRuntime] at java.lang.reflect.Method.invoke(Method.java:511)
    [AndroidRuntime] at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
    [AndroidRuntime] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
    [AndroidRuntime] at dalvik.system.NativeStart.main(Native Method)
    [AndroidRuntime] Caused by: java.lang.ClassNotFoundException: DFRS_AlHikmah.DFRS_AlHikmah.MainActivity
    [AndroidRuntime] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
    [AndroidRuntime] at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
    [AndroidRuntime] at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
    [AndroidRuntime] at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
    [AndroidRuntime] at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2015)
    [AndroidRuntime] ... 11 more
    [Process] Sending signal. PID: 17468 SIG: 9

  • AlvinKwekAlvinKwek USMember ✭✭

    I got the information from the logcat...

    Please help to see the infomration in attached log.txt

  • keithkeith USMember ✭✭

    @AlvinKwek
    can you share your main activity code where your main launcher is.
    or please check your activities if they have multiple Main Launcher = true

  • AlvinKwekAlvinKwek USMember ✭✭

    Thanks to keith n gregmunn..
    I am on Holiday now. . Will inform the detail when I return...

  • AlvinKwekAlvinKwek USMember ✭✭

    I have 2 activites:

    1. MainActivities.cs

      [Activity (MainLauncher = true,
                 ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden,
                 ScreenOrientation = ScreenOrientation.Landscape)]
      public class MainActivity : Activity
      {
      
          //SpecialKey index
          private const byte conWheelChair = 100;
          private const byte conVIP = 99;
          private const byte conThru = 98;
      
          //1.5 sec
          int intTimeOutTimer = 1500;
          //3 sec
          int intCommOutTimer = 3000;
      
          string[] arrLiftNumber = new string[9];
          //Network variables
          int Port = 6000;
          private System.Net.IPAddress IP_Address;
      
    2. ScreenSaver

      [Activity (Label = "ScreenSaver")]          
      public class ScreenSaver : Activity
      {
          private System.Timers.Timer tmrScroll;
          private bool nDirn;
          TextView tv;
          int txtwid;
      
          protected override void OnCreate (Bundle bundle)
      

    I search through the entire solution, there is only one place with "MainLauncher = true"

  • keithkeith USMember ✭✭

    @AlvinKwek please post also your XML code there's no problem in your code.

  • JamesMontemagnoJamesMontemagno USForum Administrator, Xamarin Team, Developer Group Leader Xamurai

    If you uninstall both and re-install do they both come back? Unless something is wrong in you AndroidManifest.xml... can you post that as well?

  • AlvinKwekAlvinKwek USMember ✭✭

    Below is the AndroidManifest.xml

       <?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="DFRS_AlHikmah.DFRS_AlHikmah">
        <uses-sdk />
        <application android:label="DFRS_AlHikmah" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
    
            <activity android:name=".MainActivity" android:label="DFRS_AlHikmah">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <receiver android:name=".BootupReceiver">
                <intent-filter>
                    <action android:name="android.intent.action.BOOT_COMPLETED" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </receiver>
        </application>
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    </manifest>
    

    Below is the AssemblyInfo.cs

    using System.Reflection;
    using System.Runtime.CompilerServices;
    using Android.App;
    
    // Information about this assembly is defined by the following attributes. 
    // Change them to the values specific to your project.
    [assembly: AssemblyTitle ("DFRS_AlHikmah")]
    [assembly: AssemblyDescription ("")]
    [assembly: AssemblyConfiguration ("")]
    [assembly: AssemblyCompany ("")]
    [assembly: AssemblyProduct ("")]
    [assembly: AssemblyCopyright ("Admin-Home")]
    [assembly: AssemblyTrademark ("")]
    [assembly: AssemblyCulture ("")]
    // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
    // The form "{Major}.{Minor}.*" will automatically update the build and revision,
    // and "{Major}.{Minor}.{Build}.*" will update just the revision.
    [assembly: AssemblyVersion ("1.0.0")]
    // The following attributes are used to specify the signing key for the assembly, 
    // if desired. See the Mono documentation for more information about signing.
    //[assembly: AssemblyDelaySign(false)]
    //[assembly: AssemblyKeyFile("")]
    
  • AlvinKwekAlvinKwek USMember ✭✭

    Using Xamarin connected to my device, when I Run the application from the Xamarin, I can see that two icons are created on by device.

    Using Xamarin connected to my device, when I un-install the application from the Xamarin, I can see that both icons are deleted from by Device.

    Strange thing it that, when I manually click on one of the icon, program crashed. If I click on the other icon, the program runs smoothly.

    I have not tried transferring the .apk to my device and install manual.

  • JamesMontemagnoJamesMontemagno USForum Administrator, Xamarin Team, Developer Group Leader Xamurai

    Remove this bit of XML from your AndroidManifest:

    <activity android:name=".MainActivity" android:label="DFRS_AlHikmah">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    

    That will be generated for you automatically with the attributes:
    [Activity (MainLauncher = true,
    ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden,
    ScreenOrientation = ScreenOrientation.Landscape)]

  • AlvinKwekAlvinKwek USMember ✭✭

    Hi James,

    Thank you very much. I removed the code from AndroidManifest.xml, and the duplicate icon problem is gone.

    But now I have another problem. This program is supposed to automatically launched upon power reset.
    When power reset, the program was launched but crashed.
    When I activate the program manually, it runs smoothly.

    May I know where can check about this problem?

  • rmaciasrmacias USBeta, University ✭✭✭✭✭
    <receiver android:name=".BootupReceiver">
                <intent-filter>
                    <action android:name="android.intent.action.BOOT_COMPLETED" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
    </receiver>
    

    If you're using the [IntentFilter] and [BroadcastReceiver] attributes on your BroadcastReceiver class, adding the above to the manifest is not necessary, as those attribute will automatically do it for you. Works just like the [Activity] attribute.

  • rmaciasrmacias USBeta, University ✭✭✭✭✭
    edited December 2013
  • AlvinKwekAlvinKwek USMember ✭✭

    Thanks macias. I will study the documentation. .

  • AlvinKwekAlvinKwek USMember ✭✭
    edited December 2013

    I tried to removed below from the android manifest, but the program will not start up automatically during power reset.
    Is the something else that I need to add?

    <!--        <receiver android:name=".BootupReceiver">
                <intent-filter>
                    <action android:name="android.intent.action.BOOT_COMPLETED" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </receiver>-->
    

    AndroidManifest:

    <?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="DFRS_AlHikmah.DFRS_AlHikmah">
        <uses-sdk />
        <application android:label="DFRS_AlHikmah" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
    
    <!--        <activity android:name=".MainActivity" android:label="DFRS_AlHikmah">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>-->
    <!--        <receiver android:name=".BootupReceiver">
                <intent-filter>
                    <action android:name="android.intent.action.BOOT_COMPLETED" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </receiver>-->
        </application>
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    </manifest>
    

    BootupReceiver.cs

    namespace DFRS_AlHikmah
    {
        [BroadcastReceiver]
        [IntentFilter (new[] {Intent.ActionBootCompleted})]
        class BootCompletedBroadcastMessageReceiver : BroadcastReceiver
        {
            public override void OnReceive(Context context, Intent intent)
            {
                if (intent.Action == Intent.ActionBootCompleted)
                {
                    Toast.MakeText(context, "Hello - the app has hit the right place - now to launch the app", ToastLength.Long).Show();
                    context.StartActivity(typeof(MainActivity));
                }
            }
        } 
    }
    
  • rmaciasrmacias USBeta, University ✭✭✭✭✭

    I think you left out the Category.Default.

    namespace DFRS_AlHikmah
    {
        [BroadcastReceiver]
        [IntentFilter (new[] {Intent.ActionBootCompleted, Intent.CategoryDefault})]
        class BootCompletedBroadcastMessageReceiver : BroadcastReceiver
        {
            public override void OnReceive(Context context, Intent intent)
            {
                if (intent.Action == Intent.ActionBootCompleted)
                {
                    Toast.MakeText(context, "Hello - the app has hit the right place - now to launch the app", ToastLength.Long).Show();
                    context.StartActivity(typeof(MainActivity));
                }
            }
        } 
    }
    
  • AlvinKwekAlvinKwek USMember ✭✭

    Hi Macias, I added Category.Default attribute to BroadcastReceiver Class but the application is still not startig automatically after power reset.

  • keithkeith USMember ✭✭
    edited December 2013

    @AlvinKwek try this

          [BroadcastReceiver]
        [IntentFilter(new[] { Android.Content.Intent.ActionBootCompleted },
        Categories = new[] { Android.Content.Intent.CategoryDefault })]
    
        public class Receiver1 : BroadcastReceiver
        {
            public override void OnReceive(Context context, Intent intent)
            {
                Toast.MakeText(context, "Received intent!", ToastLength.Short).Show();
    
                if ((intent.Action != null) &&
                (intent.Action == Android.Content.Intent.ActionBootCompleted))
                { // Start the service or activity
                    Android.Content.Intent start = new Android.Content.Intent(context, typeof(MainActivity));
    
                    start.AddFlags(ActivityFlags.NewTask);
    
                    //  context.ApplicationContext.StartActivity(start);
                    context.StartActivity(start);
                }
    
  • AlvinKwekAlvinKwek USMember ✭✭

    Hi Keith,

    I tried your codes..I think the program started up but stops and crashes immediately.

    Below is my code

    [BroadcastReceiver]
        [IntentFilter(new[] { Android.Content.Intent.ActionBootCompleted },
            Categories = new[] { Android.Content.Intent.CategoryDefault })]
        public class BootCompletedBroadcastMessageReceiver : BroadcastReceiver
        {
            public override void OnReceive(Context context, Intent intent)
            {
                Toast.MakeText (context, "Received intent!", ToastLength.Short).Show ();
    
                if ((intent.Action != null) && (intent.Action == Android.Content.Intent.ActionBootCompleted)) { // Start the service or activity
                    Android.Content.Intent start = new Android.Content.Intent (context, typeof(MainActivity));
    
                    start.AddFlags (ActivityFlags.NewTask);
    
                    //context.ApplicationContext.StartActivity(start);
                    context.StartActivity (start);
                }
            }
        }
    
  • keithkeith USMember ✭✭

    @AlvinKwek

        namespace DFRS_AlHikmah
        {
      [BroadcastReceiver]
        [IntentFilter(new[] { Android.Content.Intent.ActionBootCompleted },
        Categories = new[] { Android.Content.Intent.CategoryDefault })]
    
        public class Receiver1 : BroadcastReceiver
        {
            public override void OnReceive(Context context, Intent intent)
            {
                Toast.MakeText(context, "Received intent!", ToastLength.Short).Show();
    
                if ((intent.Action != null) &&
                (intent.Action == Android.Content.Intent.ActionBootCompleted))
                { // Start the service or activity
                    Android.Content.Intent start = new Android.Content.Intent(context, typeof(MainActivity));
    
                    start.AddFlags(ActivityFlags.NewTask);
    
                     context.ApplicationContext.StartActivity(start);
                   // context.StartActivity(start);
        }
    }
    }
    
  • AlvinKwekAlvinKwek USMember ✭✭
    edited December 2013

    Hi Keith,

    I tried your codes. The application seems to have statrted automatically, but stopped and crashed immediately. How can i debug this?

  • keithkeith USMember ✭✭

    @AlvinKwek the code above i shared works for me sir, it will automatically started the app after reboot. can you post the error or how it crashed. it crashed after the reboot??

  • AlvinKwekAlvinKwek USMember ✭✭
    edited December 2013

    Hi Keith... It works now..
    I forgotten to remove belows codes from Androidmanifest

    <!--        <receiver android:name=".BootupReceiver">
                <intent-filter>
                    <action android:name="android.intent.action.BOOT_COMPLETED" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </receiver>-->-->
    

    Thank you (Keith, Gregmunn, mhutch, rmacias and JamesMontemagno) so much for spending your time helping me...

    Regards,
    AK

  • AlvinKwekAlvinKwek USMember ✭✭

    For the benefits of others I would like to summarized the codes which I have implemented for my project to automatically starts up..

    Androidmanifest.xml

    <?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="DFRS_AlHikmah.DFRS_AlHikmah">
        <uses-sdk />
            <application android:label="DFRS_AlHikmah" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
    
    
                </application>
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    </manifest>
    

    Bootupreceiver.cs

    namespace DFRS_AlHikmah
    {
        [BroadcastReceiver]
        [IntentFilter(new[] { Android.Content.Intent.ActionBootCompleted },
            Categories = new[] { Android.Content.Intent.CategoryDefault })]
    
        public class Receiver1 : BroadcastReceiver
        {
            public override void OnReceive(Context context, Intent intent)
            {
                Toast.MakeText(context, "Received intent!", ToastLength.Short).Show();
    
                if ((intent.Action != null) &&
                    (intent.Action == Android.Content.Intent.ActionBootCompleted))
                { // Start the service or activity
                    Android.Content.Intent start = new Android.Content.Intent(context, typeof(MainActivity));
    
                    start.AddFlags(ActivityFlags.NewTask);
    
                    context.ApplicationContext.StartActivity(start);
                    // context.StartActivity(start);
                }
            }
        }
    }
    

    MainActivities.cs

    [Activity (MainLauncher = true,
                   ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden,
                   ScreenOrientation = ScreenOrientation.Landscape)]
        public class MainActivity : Activity
        {
    
            //SpecialKey index
            private const byte conWheelChair = 100;
            private const byte conVIP = 99;
            private const byte conThru = 98;
    ...
    
  • AndyBell.1202AndyBell.1202 GBMember

    Hi I would just like to state that this is the only post I have found which has solved my issue - so many other posts on other forums and blogs have described how the manifest must contain details of the receiver but only here have I seen a solution that worked. I now have an app which launches a service when the device is booted.

    Many thanks for saving the last remaining hairs on my head !!

  • PaulHoetsPaulHoets USMember ✭✭

    @Greg.9644 said:
    Could it be that you have 2 activities with

    MainLauncher = true

    Cool stuff - this was my reason for seeing double.

    I have a splash screen, but somehow along the way added mainlauncher = true to the main activity.

    Thanks!

  • ManojkumarMaliManojkumarMali USMember ✭✭✭

    Thanks @Greg.9644

  • RakeshAndrotulaRakeshAndrotula USMember
    edited April 2017

    @Greg.9644 said:
    Could it be that you have 2 activities with

    MainLauncher = true

    Thanks @Greg.9644.
    Your suggestion helped me. I was having the duplicate in SpashActivity!!!

  • kingleroygkingleroyg ZAMember ✭✭
    edited May 2017

    @keith said:
    @AlvinKwek
    can you share your main activity code where your main launcher is.
    or please check your activities if they have multiple Main @AlvinKwek

    Thanks @AlvinKwek , I had used MainLauncher = true in my splashscreen and MainActivity

  • mauriciomoccelinmauriciomoccelin BRMember ✭✭

    @ShaneMunn Resolveu.

    a.png 57.4K
Sign In or Register to comment.