我正在使用 Xamarin,当我单击具有电话号码链接的 TextView 时,我的模拟器执行错误。
应用程序输出具有以下输出:
[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?
我需要在哪里设置标志,我应该设置什么?
我可以得到一些帮助来让它工作吗?
提前致谢。
编辑
这是我的应用程序代码:
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);
}
}
}
在上面的代码中,我应该在哪里放置 Intent 标志?
EDIT2
这是我使用 ActivityFlags.NewTask 启动 Activity 的代码
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);
}
}
}
但是,现在出现这个错误:
android.util.SuperNotCalledException: Activity {TestTextViewAutoLink.TestTextViewAutoLink/testtextviewautolink.MainActivity} did not call through to super.onCreate()
如何让这段代码正常工作?
最佳答案
您错过了在父类(super class)中编写对 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);
}
关于c# - Activity 需要 FLAG_ACTIVITY_NEW_TASK 标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21086272/