Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Android

Back in the Android application, modify TwitterActivity and attach a handler to the client’s MentionReceived event in OnCreate(). When the event is fired, show an alert dialog with the tweet’s text (see Example 4-16), making sure to do it on the UI thread. Running the application should result in something similar to Figure 4-6.

Example 4-16. TwitterActivity.cs (updates only)

using Android.App;
using Android.OS;
using Android.Widget;
using SharedLibrary.Chapter4;

namespace Chapter4.MonoAndroidApp
{
    [Activity (Label = "\\@OReillyMedia", MainLauncher = true)]
    public class TwitterActivity : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            // ...code from last section...

            client.MentionReceived += (object sender, MentionEventArgs args) =>
            {
                RunOnUiThread(() =>
                {
                    new AlertDialog.Builder(this)
                        .SetTitle ("Mention Received")
                        .SetMessage(args.Tweet.Text)
                        .SetPositiveButton("Ok", delegate { })
                        .Show();
                });
            };
        }
    }
}
Mention received on Android

Figure 4-6. Mention received on Android

  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint