The action requires the flag FLAG_ACTIVITY_NEW_TASK

I am using Xamarin and my emulator is making an error when I click on a TextView that has a link to a phone number.

The application output has this output:

[MessageQueue-JNI] Exception in MessageQueue callback: handleReceiveCallback
[MessageQueue-JNI] android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

Where do I need to set a flag and how to set it?

Can I get some help to make this work?

Thanks in advance.

EDIT

Here is my application code:

namespace TestTextViewAutoLink
{
    [Activity (Label = "TestTextViewAutoLink", MainLauncher = true)]
    public class MainActivity : Activity
    {
        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

            TextView textView = new TextView (this.ApplicationContext);
            textView.AutoLinkMask = Android.Text.Util.MatchOptions.PhoneNumbers; 
            textView.Text = "This is a phone number 0800 32 32 32";

            //Linkify.AddLinks(textView, MatchOptions.PhoneNumbers);

            SetContentView(textView);
        }
    }
}

Where, in the code above, should I put the Intent flag?

EDIT2

Here is my code to get started with ActivityFlags.NewTask

namespace TestTextViewAutoLink
{
    [Activity (Label = "TestTextViewAutoLink", MainLauncher = true)]
    public class MainActivity : Activity
    {
        protected override void OnCreate (Bundle bundle)
        {
            Intent intent= new Intent(this.ApplicationContext, typeof(AutoLinkActivity));
            intent.SetFlags(ActivityFlags.NewTask);
            StartActivity(intent);
        }
    }
}

However, now this error occurs:

android.util.SuperNotCalledException: Activity {TestTextViewAutoLink.TestTextViewAutoLink / testtextviewautolink.MainActivity} is not called for super.onCreate ()

How can I make this code work?

+4
2

onCreate

base.OnCreate(bundle);

protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);
            Intent intent= new Intent(this.ApplicationContext, typeof(AutoLinkActivity));
            intent.SetFlags(ActivityFlags.NewTask);
            StartActivity(intent);
        }
+4

.

Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
0

All Articles