toast

Comparing two times in android

人走茶凉 提交于 2019-11-30 14:20:25
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. In other cases above code is working fine. Where I am doing wrong. Please help me. Change

Android PendingIntent介绍

自作多情 提交于 2019-11-30 11:34:42
1、PendingIntent作用 根据字面意思就知道是延迟的intent,主要用来 在某个事件完成后执行特定的Action 。PendingIntent包含了Intent及Context,所以就算Intent所属程序结束,PendingIntent依然有效,可以在其他程序中使用。 常用在通知栏及短信发送系统中。 PendingIntent一般作为参数传给某个实例,在该实例完成某个操作后自动执行PendingIntent上的Action,也可以通过PendingIntent的send函数手动执行,并可以在send函数中设置OnFinished表示send成功后执行的动作。 2、PendingIntent举例 a. 系统通知栏 NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); int icon = android.R.drawable.stat_notify_chat; long when = System.currentTimeMillis() + 2000 ; Notification n = new Notification(icon, "通知栏demo提醒" , when); n.defaults = Notification

Toast message from Broadcast Receiver

旧巷老猫 提交于 2019-11-30 11:17:23
I have a broadcast receiver and I am trying to show a toast message from it, is this possible ? This code doesn't show the toast but it print the log message in the logcat. Is there some idiotic thing I am doing or what is my problem ? @Override public void onReceive(Context context, Intent intent) { Log.v("log", "this is shown"); Toast.makeText(context, "this is not shown" , Toast.LENGTH_LONG); } Call the show() method for the Toast . you forgot to call show() on the Toast .. although i would not recommend creating toasts from BroadcastReceivers.. you might consider using Notifications Use

Showing Windows 8 toast from Windows Forms App

半腔热情 提交于 2019-11-30 09:30:15
We've got a Windows Forms Application (vs. WPF) that was originally created for Windows 7. We're carrying the product forward to be used in Windows 8. Is it possible to show Windows 8 Toast Notifications (Windows.UI.Notifications namespace) from this WinForm app, for users running Windows 8? I can't seem to find any examples. Everything I find is a WPF or Windows Store apps—no examples are WinForm apps. It is possible to use toast notification in winform poject under win 8. I create a winform project, add a button, when pressing the button, there will be a toast notification showed in the

How do I make a toast from a non activity class?

主宰稳场 提交于 2019-11-30 09:12:46
问题 I have a class that I am using to get GPS data within my activity. In the constructor I pass it the activity's context: gpsFetcher = new GPSFetcher(this); and in the gpsFetcher class I have: this.context = c.getApplicationContext(); OR just this.context = c; and then I call the toast with: Toast.makeText(context, "sometext", Toast.LENGTH_LONG); But it never shows up... Is there something I'm missing? Is it possible? Thanks! 回答1: Are you forgetting Toast#show ? Toast toast = Toast.makeText

Android 点击按钮弹出菜单

筅森魡賤 提交于 2019-11-30 07:53:57
效果图: 1、创建menu文件夹,新建main.xml文件 <?xml version="1.0" encoding="utf-8"?><menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/add" android:title="添加" /> <item android:id="@+id/remove" android:title="删除" /> <item android:id="@+id/share" android:title="分享" /></menu>2、在MainActivity 中 public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ImageView imageVie = findViewById(R.id.main_img); imageVie.setOnClickListener(new View

Center text in a toast in Android

不想你离开。 提交于 2019-11-30 06:22:20
问题 I was wondering if there was a way to display all text in a toast to be centered. For instance, I have a toast that has 2 lines of text in it. For purely aesthetic reasons, I would like the text to center-aligned instead of left-aligned. I've looked through the documentation and can't find anything about it. Is there a simple way to do this that I have missed? Thanks Chris 回答1: Use the Toast's setView(view) function to supply a View with Gravity.CENTER . 回答2: Adapted from another answer:

Android 避免内存泄漏

岁酱吖の 提交于 2019-11-30 05:44:02
什么是内存泄露?   就是该回收的内存由于种种原因没有被回收,还驻留在内存中。 内存泄露有什么影响?   可能一处小小的内存泄露就会导致整个应用卡顿,甚至崩溃。 例子说明:   Toast.makeText(MainActivity.this,"Hello",Toast.LENGTH_SHORT).show();   这段代码可能会出现内存泄露。 为什么说可能会造成内存泄露?   如果在Toast消失之前,Toast 持有了当前的 Activity,而此时,用户点击了返回键,导致 Activity 无法被 GC(Garbage Collection垃圾回收) 回收,这个Activity 就引起了内存泄露。 解决方法?   所有和当前 Activity 无关的 Context 都可以传入,避免内存泄露的方法同样使用其他需要传入 Context 的地方。(这句话我表示理解不了)如下 Toast.makeText(getApplicationContext(),"Hello",Toast.LENGTH_SHORT).show();   getApplicationContext()是整个应用的上下文,不会持有某个 Activity 对象。 注意   dialog的上下文不能使用getApplicationContext(),程序会崩掉,dialog实例化必须持有 Activity对象。

ToastNotifications sent from PowerShell disappear from Action Center

自作多情 提交于 2019-11-30 04:12:56
I'm using this code to send notifications from PowerShell script. PowerShell itself is launched by (persistent) Java application. [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] > $null [Windows.UI.Notifications.ToastNotification, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null $xml = New-Object Windows.Data.Xml.Dom.XmlDocument $template = "<toast><visual><binding template=`"ToastText02`"><text id=`"1`">Title<

menu和actionbar

随声附和 提交于 2019-11-30 03:35:14
3.0之后推荐用actionbar,Menu已经过时但是我们还是了解一下吧, Menu学习 在java语句中添加menu组件 重写onCreateOptionsMenu(Menu menu)方法 @Override public boolean onCreateOptionsMenu(Menu menu) { MenuItem menuItem1 = menu.add(100, 100, 1, "系统菜单"); menuItem1.setIcon(R.drawable.ic_launcher_background); menuItem1.setTitle("菜单一"); MenuItem menuItem2 = menu.add(100, 101, 2, "系统菜单"); menuItem2.setIcon(R.drawable.ic_launcher_background); menuItem2.setTitle("菜单二"); MenuItem menuItem3 = menu.add(100, 102, 3, "系统菜单"); menuItem3.setIcon(R.drawable.ic_launcher_background); menuItem3.setTitle("菜单三"); return super.onCreateOptionsMenu(menu); }