ASKER
ASKER
private async Task PullAllDataFunction(Message msg, Context _Context)
{
ShowMessage(_Context, _Context.GetString(Resource.String.downloading_Items));
await PullData.GetInstance().FetchITemsDataAsync();
ShowMessage(_Context, _Context.GetString(Resource.String.Customers));
await PullData.GetInstance().FetchCustomersDataAsync();
CompletedSelfResult(_Context, msg.Arg1); //here a message that downloading data has been completed
}
show message function:
private void ShowMessage(Context _Context, string m_Message)
{
var m_thread = new Java.Lang.Thread(() =>
{
Task.Run(() =>
{
try
{
Toast.MakeText(outerInstance, m_Message, ToastLength.Long).Show();
}
catch
{
ToastUtils.ShowMessage(_Context, m_Message);
}
}).ConfigureAwait(false);//ConfigureAwait is used to avoid deadlocks
});
m_thread.Start();
//
}
public class ToastUtils
{
static Toast toast = null;
public static void ShowMessage(Context context, System.String m_Message)
{
try
{
DisplayMessage(context, m_Message);
}
catch (System.Exception ex)
{
Log.Debug(TAG, ex.ToString());
}
}
public static void DisplayMessage(Context context, System.String m_Message)
{
try
{
if (toast != null)
{
toast.SetText(m_Message);
}
else
{
Toast.MakeText(context, m_Message, ToastLength.Long).Show();
}
toast.Show();
}
catch
{
Looper.Prepare();//checks if there is no Looper already attached to our Thread (remember, only one Looper per Thread) and then creating and attaching a Looper.
Toast.MakeText(context, m_Message, ToastLength.Long).Show();
Looper.Loop();//cause our Looper to start looping.
}
}
}
ASKER
public class ToastUtils
{
static Toast toast = null;
public static void ShowMessage(Context context, System.String m_Message)
{
try
{
DisplayMessage(context, m_Message);
ClearMessage(context, m_Message);
}
catch (System.Exception ex)
{
Log.Debug(TAG, ex.ToString());
}
}
public static void ClearMessage(Context context, System.String m_Message)
{
toast.SetText(m_Message);
toast.Cancel();
}
public static void DisplayMessage(Context context, System.String m_Message)
{
try
{
toast = Toast.MakeText(context, m_Message, ToastLength.Long);
toast.Show();
}
catch
{
Looper.Prepare();//checks if there is no Looper already attached to our Thread (remember, only one Looper per Thread) and then creating and attaching a Looper.
toast = Toast.MakeText(context, m_Message, ToastLength.Long);
toast.Show();
Looper.Loop();//cause our Looper to start looping.
}
}
}
Android is a mobile operating system developed by Google, based on the Linux kernel and designed primarily for touchscreen mobile devices such as smartphones and tablets. Android's user interface is based on direct manipulation, using touch gestures that loosely correspond to real-world actions, such as swiping, tapping and pinching, to manipulate on-screen objects, along with a virtual keyboard for text input. In addition to touchscreen devices, variants of Android are also used on notebooks, game consoles, digital cameras, televisions, automobiles and other electronics. Applications are usually developed in Java programming language using the Android software development kit (SDK), but other development environments are also available, including Delphi, Ruby and Visual Studio (using C++).
TRUSTED BY