不管什么语言,了解信息的输出可谓紧要的事情,如vb的msgbox,js的alert,c#的MessageBox.Show,这个对于调试意义重大。Android的输出方法有:

一、用Log输出。共分Log.v,Log.d,Log.i,Log.w,Log.e,和Log4Net差不多了,用颜色区分,在LogCat窗口中查看。

二、用AlertDialog。将弹出窗口,并可以处理返回事件

import android.app.AlertDialog;
import android.content.DialogInterface;

            new AlertDialog.Builder(login.this)
            .setTitle("这是提示!")
            .setMessage("这是提示的内容")
            .setPositiveButton("关闭",new DialogInterface.OnClickListener(){public void onClick(DialogInterface di, int ii){}})
            .show();

三、在信息栏显示。用Toast.makeText命令。

Toast.makeText(this,"test info",Toast.LENGTH_SHORT).show();

四、在状态栏显示。因为涉及到单击后进入另外一个Activity,所以工作量较多。

假设已经存在一个新的Acivity名为newact,参见

NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification n = new Notification(R.drawable.icon, "Hello,there!", System.currentTimeMillis());             
n.flags = Notification.FLAG_AUTO_CANCEL;
Intent i=new Intent();
i.setClass(add2.this, newact.class);
PendingIntent pi=PendingIntent.getActivity(this, 0, i, 0);
n.setLatestEventInfo(this, "button1", "button1的通知", pi);
nm.notify(R.string.app_name, n);

关于通知的更详细的设置参见

相关文章:

  • 2021-05-18
  • 2022-01-06
  • 2021-10-25
  • 2022-12-23
  • 2021-07-11
  • 2022-12-23
  • 2021-07-24
  • 2021-08-25
猜你喜欢
  • 2021-05-20
  • 2021-12-22
  • 2021-07-21
  • 2021-04-18
  • 2022-12-23
  • 2021-12-15
  • 2022-12-23
相关资源
相似解决方案