[FIXED] IntentFilter in Xamarin gives error "java.exe exited with code 1"

Issue

I’m trying to understand how actions in xamarin work and i tried to add some of them to my activity. It builds with error "java.exe exited with code 1". I found that the same code works in my main launcher activity, but it doesn’t compile when I’m adding it to the other activities.

I tried to search for answer, but there is no topic with that question, so i decide to write here for help.

This is my first time questioning btw ._.

this code builds

namespace XamarinLearningField
{
    [Activity(Label = "SomeApp", Theme = "@style/AppTheme", MainLauncher = true)]
    [IntentFilter(new[] { Intent.ActionView },
        Categories = new[] { Intent.CategorySampleCode, "my.custom.category" })]
    public class MainActivity : AppCompatActivity, Android.Views.View.IOnClickListener
    {
        TextView tvName;
        Button btnName;

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);

            tvName = (TextView)FindViewById(Resource.Id.tvName);
            btnName = (Button)FindViewById(Resource.Id.btnName);
            btnName.SetOnClickListener(this);

            Button btnTime = (Button)FindViewById(Resource.Id.btnTime);
            Button btnDate = (Button)FindViewById(Resource.Id.btnDate);

            btnTime.SetOnClickListener(this);
            btnDate.SetOnClickListener(this);
        }
}

this not

{
    [Activity(Label = "Data/Time info", MainLauncher = false)]
    [IntentFilter(new[] { "en.startandroid.intent.action.showtime","en.startandroid.intent.action.showdate" },
        Categories = new[] { Intent.CategoryDefault })]
    public class InfoActivity : AppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Info_ActivityLayout);

          
            Intent intent = this.Intent;
            String action = intent.Action;
            String format = "", textInfo = "";

            if (action.Equals("en.startandroid.intent.action.showtime"))
            {
                format = "HH:mm:ss";
                textInfo = "Time: ";
            }
            else if (action.Equals("en.startandroid.intent.action.showdate"))
            {
                format = "dd.MM.yyyy";
                textInfo = "Date: ";
            }

            ...
}

Solution

I added "Exported = false" to Attributes of my extra Activity and it worked.

the code will be like that:

 [Activity(Label = "Data/Time info", Exported = false)]
    [IntentFilter(new[] { "en.startandroid.intent.action.showtime","en.startandroid.intent.action.showdate" },
        Categories = new[] { Intent.CategoryDefault })]
    public class InfoActivity : AppCompatActivity
    {
       ...

Answered By – Max Esin

Answer Checked By – Laura B. (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published