2014-01-13 36 views
4

我正在使用Xamarin,当我点击一个TextView时,我的模拟器正在执行错误,该TextView有一个电话号码的链接。活动需要FLAG_ACTIVITY_NEW_TASK标志

应用输出有这样的输出:

[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); 
     } 
    } 
} 

其中,在上面的代码,我应该放在意向标志?

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:活动{TestTextViewAutoLink.TestTextViewAutoLink/testtextviewautolink.MainActivity}没有通过调用super.onCreate()

我该如何获得此代码的工作?

+0

[选中此选项(http://stackoverflow.com/questions/8599657/dialing-a-phone-call-on-click-of-textview-in-android) –

+0

'没叫通过super.onCreate()'add super.onCreate() –

回答

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); 
4

你错过了写在超类

基地要求的onCreate功能。 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); 
     } 
相关问题