本文整理汇总了C#中Android.OS.Handler.Post方法的典型用法代码示例。如果您正苦于以下问题:C# Handler.Post方法的具体用法?C# Handler.Post怎么用?C# Handler.Post使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.OS.Handler
的用法示例。
在下文中一共展示了Handler.Post方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunOnMainThread
protected void RunOnMainThread(Action action)
{
Handler handler = new Handler(Looper.MainLooper);
handler.Post(action);
handler.Dispose();
handler = null;
}
示例2: BeginGeofencing
public void BeginGeofencing(object sender, EventArgs eventArgs)
{
if (!apiClient.IsConnected) {
var myHandler = new Handler ();
myHandler.Post (() => {
Android.Widget.Toast.MakeText (this, "Google API Not Connected. Try Again.", Android.Widget.ToastLength.Long).Show ();
});
return;
}
try {
if (connectedGeofences.Count >= 1) {
LocationServices.GeofencingApi.AddGeofences(apiClient, getGeofencingRequest(), getGeofencePendingIntent()).SetResultCallback(this);
string geofenceAnnounce = "Geofences Active At The Following Locations:\n";
foreach (ROMPGeofence geofName in connectedGeofences) {
geofenceAnnounce += geofName.Id + "\n";
}
var myHandler = new Handler ();
myHandler.Post (() => {
Android.Widget.Toast.MakeText (this, geofenceAnnounce, Android.Widget.ToastLength.Long).Show ();
});
FindViewById<Button>(Resource.Id.btnBegin).Visibility = ViewStates.Invisible;
FindViewById<TextView>(Resource.Id.lblConfirm).SetText("A record that you have checked-in will be made in the log of your education activity for this ROMP rotation when this device enters a 1km radius surrounding the facility of your ROMP rotation.", TextView.BufferType.Normal);
geofenceRequestIntent = PendingIntent.GetService (this, 0,
new Intent (this, Java.Lang.Class.FromType (typeof(GeofenceTransitionsIntentService))),
PendingIntentFlags.UpdateCurrent);
} else {
FindViewById<Button>(Resource.Id.btnBegin).Visibility = ViewStates.Invisible;
FindViewById<TextView>(Resource.Id.lblConfirm).SetText("No Rotations Available, Please Try Within Your Scheduled Rotation Dates", TextView.BufferType.Normal);
}
} catch (SecurityException securityEx) {
logSecurityException (securityEx);
}
}
示例3: CreateNotifications
private void CreateNotifications(Context context, string action, bool isMessageNeeded = true, bool isToastNeeded = true)
{
#if DEBUG
try {
if (isMessageNeeded)
{
Notification notification = new Notification.Builder(context)
.SetContentTitle ("BluetoothNotify intent received " + action)
.SetContentText ("message sent at" + System.DateTime.Now.ToLongTimeString ())
.SetSmallIcon (Resource.Drawable.icon)
.Build ();
NotificationManager nMgr = (NotificationManager)context.GetSystemService (Android.Content.ContextWrapper.NotificationService);
nMgr.Notify (0, notification);
}
if (isToastNeeded)
{
var myHandler = new Handler ();
myHandler.Post (() => {
Toast.MakeText (context, "BluetoothNotify intent received " + action, ToastLength.Long).Show ();
});
}
} catch (Exception ex) {
Log.Info ("com.tarabel.bluetoothnotify", "CreateNotification error in IntentReceiver " + ex.ToString());
}
#endif
}
示例4: Peer_PeerConnected
private void Peer_PeerConnected (object sender, PeerConnectedEventArgs args)
{
using (var h = new Handler (Looper.MainLooper))
h.Post (() => {
textView.Text = args.PeerId;
});
}
示例5: OnClick
public void OnClick(View v)
{
Handler h = new Handler();
h.Post(() => {
this.Img.StartAnimation(this.AniSet);
});
}
示例6: OnLayout
protected override void OnLayout (bool changed, int l, int t, int r, int b)
{
using (var h = new Handler (Looper.MainLooper)) {
h.Post (() => {
double width = base.Context.FromPixels ((double)(r - l));
double height = base.Context.FromPixels ((double)(b - t));
var size = new Size (width, height);
var msw = MeasureSpec.MakeMeasureSpec (r - l, MeasureSpecMode.Exactly);
var msh = MeasureSpec.MakeMeasureSpec (b - t, MeasureSpecMode.Exactly);
_nativeView.Measure (msw, msh);
_nativeView.Layout (0, 0, r - l, b - t);
// if (size != _previousSize) {
var layout = _viewCell.View as Layout<Xamarin.Forms.View>;
if (layout != null) {
layout.Layout (new Rectangle (0, 0, width, height));
layout.ForceLayout ();
FixChildLayouts (layout);
_isLaidOut = true;
}
_previousSize = size;
});
}
// }
}
示例7: Update
public void Update (object bindingContext)
{
using (var h = new Handler (Looper.MainLooper)) {
h.Post (() => {
_viewCell.BindingContext = bindingContext;
});
}
}
示例8: StartPlayingHandler
private void StartPlayingHandler()
{
var handler = new Handler();
var runnable = new Runnable(() => { handler.Post(OnPlaying); });
if (!_executorService.IsShutdown)
{
_scheduledFuture = _executorService.ScheduleAtFixedRate(runnable, 100, 1000, TimeUnit.Milliseconds);
}
}
示例9: Invoke
public void Invoke(Action action)
{
//Another method
//http://stackoverflow.com/questions/11123621/running-code-in-main-thread-from-another-thread
var l = Android.OS.Looper.MainLooper; //Previously Context.GetMainLooper()
Handler mainHandler = new Handler(l);
Runnable myRunnable = new Runnable(action);
mainHandler.Post(myRunnable);
}
示例10: OnCreate
protected override void OnCreate(Bundle bundle)
{
RequestWindowFeature(WindowFeatures.NoTitle);
base.OnCreate (bundle);
SetContentView (Resource.Layout.ChooseMode);
try {
string sessionKey = Intent.GetStringExtra ("SessionKey");
int groupID = Intent.GetIntExtra ("GroupID", 0);
int userID = Intent.GetIntExtra ("UserID", 0);
var locSvc = new ROMPLocation ();
Button button = FindViewById<Button> (Resource.Id.btnChoose);
CheckBox cbpassive = FindViewById<CheckBox> (Resource.Id.cbPassive);
CheckBox cbactive = FindViewById<CheckBox> (Resource.Id.cbActive);
cbpassive.Click += (o, e) => {
if (cbactive.Checked) {
cbactive.Checked = false;
}
};
cbactive.Click += (o, e) => {
if (cbpassive.Checked) {
cbpassive.Checked = false;
}
};
button.Click += delegate {
if (cbactive.Checked) {
var nextActivity = new Intent(this, typeof(CheckInActivity));
nextActivity.PutExtra("SessionKey", sessionKey);
nextActivity.PutExtra("GroupID", groupID);
nextActivity.PutExtra("UserID", userID);
StartActivity(nextActivity);
Finish();
} else if (cbpassive.Checked) {
var nextActivity = new Intent(this, typeof(CheckInPassiveActivity));
nextActivity.PutExtra("SessionKey", sessionKey);
nextActivity.PutExtra("GroupID", groupID);
nextActivity.PutExtra("UserID", userID);
StartActivity(nextActivity);
Finish();
} else {
string errmsg = "Please choose a check in method before proceeding.";
var myHandler = new Handler();
myHandler.Post(() => {
Toast.MakeText(this, errmsg, ToastLength.Short).Show();
});
}
};
} catch (Exception e) {
var myHandler = new Handler();
myHandler.Post(() => {
Android.Widget.Toast.MakeText(this, e.Message, Android.Widget.ToastLength.Long).Show();
});
System.Diagnostics.Debug.Write (e.Message);
}
}
示例11: Send
public override void Send(SendOrPostCallback d, object state)
{
var looper = Looper.MainLooper;
if (Looper.MyLooper() == looper) {
d (state);
return;
}
var m = new ManualResetEvent (false);
using (Handler h = new Handler (looper)) {
h.Post (() => {
d (state);
m.Set ();
});
}
m.WaitOne ();
}
示例12: GridViewCellContainer
public GridViewCellContainer (Context context, FastGridCell fastGridCell, global::Android.Views.View parent, Size initialCellSize) : base (context)
{
using (var h = new Handler (Looper.MainLooper)) {
h.Post (() => {
_parent = parent;
_viewCell = fastGridCell;
fastGridCell.PrepareCell (initialCellSize);
// _viewCell.View.BackgroundColor = Xamarin.Forms.Color.Green;
var renderer = fastGridCell.View.GetOrCreateRenderer ();
_nativeView = renderer.ViewGroup;
// SetBackgroundColor (Android.Graphics.Color.Yellow);
AddView (_nativeView);
});
}
}
示例13: OnHandleIntent
protected override void OnHandleIntent(Intent intent)
{
// Can use intent to pass data to the service.
var val = intent.GetStringExtra(IntentValueKey);
// IntentService uses queued worker threads. To do something on the UI we must invoke on the main thread.
var handler = new Handler(Looper.MainLooper);
handler.Post(() => {
Toast.MakeText(this, $"OnHandleIntent({val})", ToastLength.Long).Show();
});
for(int i = 1; i < 20; i++)
{
MainActivity.L($"Processing...{i}");
Thread.Sleep(1000);
}
}
示例14: CreateNotifications
void CreateNotifications(string status)
{
#if DEBUG
Notification notification = new Notification.Builder (this)
.SetContentTitle ("BluetoothLowEnergySearchService " + status)
.SetContentText ("message sent at" + System.DateTime.Now.ToLongTimeString ())
.SetSmallIcon (Resource.Drawable.icon)
.Build ();
NotificationManager nMgr = (NotificationManager)GetSystemService (NotificationService);
nMgr.Notify (0, notification);
var myHandler = new Handler ();
myHandler.Post (() => {
Toast.MakeText (this, "BluetoothLowEnergySearchService "+ status, ToastLength.Long).Show ();
});
#endif
}
示例15: GetDeviceList
public List<string> GetDeviceList(Context context)
{
List<string> result = new List<string> ();
// Get local Bluetooth adapter
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.DefaultAdapter;
// If the adapter is null, then Bluetooth is not supported
if (bluetoothAdapter == null) {
var myHandler = new Handler ();
myHandler.Post (() => {
Toast.MakeText (context, "Bluetooth is not available", ToastLength.Long).Show ();
});
return result;
}
// If bluetooth is not enabled, ask to enable it
if (!bluetoothAdapter.IsEnabled)
{
var myHandler = new Handler ();
myHandler.Post (() => {
Toast.MakeText (context, "Bluetooth is not enabled, please enable it", ToastLength.Long).Show ();
});
var enableBtIntent = new Intent(BluetoothAdapter.ActionRequestEnable);
}
// Get connected devices
var listOfDevices = bluetoothAdapter.BondedDevices;
if (listOfDevices.Count > 0)
{
foreach (var bluetoothDevice in listOfDevices)
{
if (!result.Contains(bluetoothDevice.Name + ":" + bluetoothDevice.Address))
result.Add(bluetoothDevice.Name + ":" + bluetoothDevice.Address);
}
}
return result;
}