当我点击带有电话号码链接的TextView时,我正在使用Xamarin并且我的模拟器正在执行错误。
应用程序输出具有此输出:
[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
启动活动的代码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}没有调用super.onCreate()
如何让此代码正常工作?
答案 0 :(得分:5)
您错过了在超类
中为onCreate函数编写调用base.OnCreate(捆绑);
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
Intent intent= new Intent(this.ApplicationContext, typeof(AutoLinkActivity));
intent.SetFlags(ActivityFlags.NewTask);
StartActivity(intent);
}
答案 1 :(得分:0)
试试这个..
错误本身具有含义
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);