什么"警告:方法X已过时:'已弃用'"意思?

时间:2015-07-19 22:14:52

标签: c# android xamarin

演讲在我的真实设备上运行良好。

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Speech.Tts;

namespace App7
{
    [Activity(Label = "App7", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity, TextToSpeech.IOnInitListener
    {
        public TextToSpeech SpeechText
        {
            get;
            set;
        }

        int count = 1;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);


            // create text to speech object to use synthesize and speak functions.
            // first parameter: context
            // second parameter: object implemeting TextToSpeech.IOnInitListener
            this.SpeechText = new TextToSpeech(this, this);

            Button testButton = FindViewById<Button>(Resource.Id.button1);
            testButton.Click += delegate
            {
                this.SpeechText.Speak("Hello World, You shall not pass", QueueMode.Flush, null);
            };
            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button>(Resource.Id.MyButton);

            button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
        }

        public void OnInit(OperationResult status)
        {
            // here you can setup language settings

            if (status.Equals(OperationResult.Success))
                Toast.MakeText(this, "Text To Speech Succeed!", ToastLength.Long).Show();
            else
                Toast.MakeText(this, "Text To Speech Fail", ToastLength.Long).Show();
        }
    }
}

警告就在这一行:

this.SpeechText.Speak("Hello World, You shall not pass", QueueMode.Flush, null);

在此行下方有一条绿线,警告信息为:

  

警告1&#39; Android.Speech.Tts.TextToSpeech.Speak(字符串,Android.Speech.Tts.QueueMode,System.Collections.Generic.IDictionary)&#39;已过时:&#39;已弃用&#39;

试图谷歌没找到任何东西。 我可以忽略它,但我想知道它是什么意思?我该如何解决?

1 个答案:

答案 0 :(得分:0)

这意味着在Xamarin中不推荐使用this overload(因为Google将其标记为deprecated as of API level 21)。

如果警告困扰您并且您的目标API级别允许,或者只是忽略该警告,请使用不被弃用的其他两个重载(12)。