public class Main extends Activity
{
private NotificationManager notificationManager;
private Notification notification;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notification = new Notification(R.drawable.ic_launcher, "", System.currentTimeMillis());
Log.d("11111111111", "Oncreate");
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(keyCode == KeyEvent.KEYCODE_BACK )
{
showDialog();//调用退出对话框
Log.d("back", "back");
}
return super.onKeyDown(keyCode, event);
}
/**如果用户按下home键,会调用onStop()。发送一个通知。通过这个通知就可以回到原来的界面,而不会调用onCreate方法*/
@Override
protected void onStop()
{
Intent notificationIntent = new Intent(Main.this, Main.class);//这个实际上只是指定启动一个Activity,这里选择本身
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.flags = Notification.FLAG_ONGOING_EVENT;//这个表示“正在进行的”,而不是“通知”
notification.setLatestEventInfo(this, "哇哈哈","哥在运行中...", contentIntent);
notificationManager.notify(R.drawable.ic_launcher, notification);
Log.d("111111111", "onStop");
super.onStop();
}
/** 重新获得焦点的时候清理notification*/
@Override
protected void onResume()
{
notificationManager.cancelAll();
super.onResume();
}
/** 创建一个对话框,确认是否退出*/
private void showDialog()
{
new AlertDialog.Builder(this).setTitle("是否退出应用程序?")
.setPositiveButton("确定", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
//finish();//如果这里执行的是finish(),则也会调用onStop()
android.os.Process.killProcess(android.os.Process.myPid());//整个结束掉,这样就不会执行onStop()
}
}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).show();
}
}
$(document).ready(function() {
alert(123);
});
完整代码
$(document).ready(function() {
//伸缩下拉菜单
$(".menu h3").click(function() {
// $(".menu ul").hide();
$(this).next().slideToggle();
$(this).css("font-weight", "bold");
});
//点击中间布局,左拉和又拉
$(".unfold").click(function() {
$("#left").show();
$("#left").width(174);
$(".fold").show();
$(this).hide();
var width = $(window).width();
$("#right").width(width - 185);
});
$(".fold").click(function() {
$("#left").hide();
$(".unfold").show();
$(this).hide();
var width = $(window).width();
$("#right").width(width - 11);
});
});
以前看到一个这样的比喻:有人(b)要来踢馆,这时候老板(A)不方便出面,找了黑道上的朋友(B)出马摆平。那么这个黑道上的朋友就是这个老板的代理。(b的事件就可以在B的代理方法中得到执行)
那么是不是可以这样理解呢?
在类A中,有一个对象b,这个b需要执行某些特殊的方法,这时候在类A的头文件中声明b的代理B(相当于告诉编译器:A和B是好朋友...(协议@protocol)),这时候再在b中delegate:self。就可以执行B中的代理方法了。
不知道这样对吗?
有点乱....希望知道的朋友给点建议。