toast

getting context in AsyncTask

谁都会走 提交于 2019-11-26 18:35:12
I am trying to get the context in my AsyncTask of the class called Opciones(this class is the only one that call that task) but I don't know how to do it, I saw some code like this: protected void onPostExecute(Long result) { Toast.makeText(Opciones.this,"Subiendo la foto. ¡Tras ser moderada empezara a ser votada!: ", Toast.LENGTH_LONG).show(); } But it doesn't work for me it says: "No enclosing instance of the type Opciones in scope" You need to do following things. when you want to use AsyncTask , extend that in other class say MyCustomTask . in constructor of new class, pass Context Example

Posting Toast message from a Thread

£可爱£侵袭症+ 提交于 2019-11-26 17:15:07
问题 My application launches a thread to query the web for some data. I want to display a Toast message when nothing is found, but my application always crashes. I've tried using the application Context from within the thread, like so: Toast.makeText(getApplicationContext(), "testttt", Toast.LENGTH_LONG).show(); I've also tried creating a Runnable with the Toast call and calling runOnUiThread(runnable) from the Thread (the Toast call in this runnable uses the Activity as the first parameter). Does

Android开发华为手机不弹出Toast,报HwRTBlurUtils: check blur style for HwToast-Toast...的原因

我与影子孤独终老i 提交于 2019-11-26 17:12:52
华为手机不弹出Toast,log报的信息:HwRTBlurUtils: check blur style for HwToast-Toast, themeResId : 0x7f0c0005, context : 。。。我的原因是:重写了getResources方法时调用了setToDefaults()方法导致的。 override fun getResources(): Resources { val resources = super.getResources() val config = resources.configuration// config.setToDefaults()  //原因就是调用了这行代码。。。 config.fontScale = 1.0f resources.updateConfiguration(config, resources.displayMetrics) return resources } 来源: https://www.cnblogs.com/yongfengnice/p/11328616.html

Comparing two times in android

不问归期 提交于 2019-11-26 16:58:05
问题 I have tried with the below code to compare two times: SimpleDateFormat sdf = new SimpleDateFormat("hh:mm"); Date inTime = sdf.parse("11:00"); Date outTime = sdf.parse("10:00"); if(inTime.compareTo(outTime) > 0){ Toast.makeText(this, "Out time should be greater than In time", Toast.LENGTH_SHORT).show(); } Above code is working fine. But if I give in time as 11:00 and out time as 12:00, I am getting above toast message. I am getting above toast message if I give out time from 12:00 to 12:59.

How to display a Toast in Android AsyncTask?

别说谁变了你拦得住时间么 提交于 2019-11-26 16:16:26
问题 I am trying to display Toast in my initial_background class extended with AsyncTask<URL, Integer, Long> . I am receiving this error in logcat. public class InitialBackgroundTask extends AsyncTask<URL, Integer, Long> { @Override protected Long doInBackground(URL... params) { // TODO Auto-generated method stub show a = new show(); a.loop(); return null; } public class show { void loop() { for(int i=0; i<10; i++) { Toast.makeText(MainActivity.me, "test", Toast.LENGTH_LONG).show(); } } } This is

How to cancel Toast

瘦欲@ 提交于 2019-11-26 16:07:01
问题 I developed an android application and I am facing a problem with Toast . Suppose I am displaying a Toast, it is displayed on the application window. When a Dialog box is appears, the toast doesn't disappear instantly . I want to know how I can cancel the toast. 回答1: Toast.makeText returns a Toast object. Call cancel() on this object to cancel it. 回答2: The shortest duration you can specify for the toast is Toast.LENGTH_SHORT which has a value of 0 but is actually 2000 milliseconds long . If

Can i have an example of displaying a toast using runOnUiThread.

走远了吗. 提交于 2019-11-26 14:12:20
问题 I searched many places but could not find a complete working example of implementation of "runOnUiThread". I tried a lot , but getting lots of errors . I just want to display a toast from a thread. 回答1: So here is the final full code. Thanks to all who have replied. import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Toast; public class MainActivity extends Activity { @Override public void onCreate(Bundle

Displaying a stock iOS notification banner when your app is open and in the foreground?

痞子三分冷 提交于 2019-11-26 14:09:42
When Apple's official iOS Messages app is open and in the foreground, new messages from other contacts trigger a stock, native iOS notification alert banner. See image below. Is this possible in 3rd party apps on the App Store? Local and/or Push Notifications for your app while your app is open and in the foreground ? When testing my app , notifications are received but no iOS alert UI is shown . But this behavior is seen in Apple's official Messages app: The Local and Remote Notification Programming Guide says: When the operating system delivers a local notification or remote notification and

What is the duration of a Toast LENGTH_LONG and LENGTH_SHORT

橙三吉。 提交于 2019-11-26 14:02:29
问题 I need the exact duration of LENGTH_LONG and LENGTH_SHORT in milliseconds (ms). Also I need to know if the duration of Toast message with LENGTH_LONG will have the same duration in any phone and with any API version. Does someone know where is the duration defined ?, I mean defined in ms . I know that LENGTH_LONG is some int const with value 1. But I could not find where is the actual duration defined. 回答1: Answered here. Like you mentioned Toast.LENGTH_SHORT and Toast.LENGTH_LONG are not in

Popup over incoming-call screen

天大地大妈咪最大 提交于 2019-11-26 13:56:04
问题 I want to create a customized popup over the android's incoming call screen where I wish to add information for the user. I want the popup to not disable any clickability from the background so that the user could still answer the call. I know it is possible since many applications do it, e.g. MeZeZe app: Some more information : A translucent theme did not work since it cancels the former activity's clickability. A toast is not an option - I don't want it to disappear. I know there are many