Last active
August 29, 2015 14:06
-
-
Save zii/01c7e65dfd0be678a15b to your computer and use it in GitHub Desktop.
android toast, dialog, openurl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.hello; | |
import android.app.Activity; | |
import android.net.Uri; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.widget.Toast; | |
import android.app.AlertDialog; | |
import android.app.Dialog; | |
import android.content.Context; | |
import android.content.DialogInterface; | |
import android.content.Intent; | |
public class MainActivity extends Activity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
Log.e("log", "oncreate"); | |
Toast.makeText(getApplicationContext(), Math.dup("g"), Toast.LENGTH_SHORT).show(); | |
} | |
@Override | |
protected void onStart() { | |
super.onStart(); | |
Log.e("log", "onstart"); | |
Dialog d = new AlertDialog.Builder(this). | |
setTitle("确定退出吗?"). | |
setMessage("hello world"). | |
setPositiveButton("确定", new DialogInterface.OnClickListener() { | |
public void onClick(DialogInterface dialog, int which) { | |
Log.e("log", "onclick ok"); | |
MainActivity.this.finish(); | |
} | |
}). | |
setNegativeButton("取消", new DialogInterface.OnClickListener() { | |
public void onClick(DialogInterface dialog, int which) { | |
Log.e("log", "onclick cancel"); | |
} | |
}). | |
setNeutralButton("详情", new DialogInterface.OnClickListener() { | |
public void onClick(DialogInterface dialog, int which) { | |
Uri uri = Uri.parse("http://www.baidu.com"); | |
Intent it = new Intent(Intent.ACTION_VIEW, uri); | |
startActivity(it); | |
} | |
}). | |
create(); | |
d.show(); | |
} | |
@Override | |
protected void onPause() { | |
super.onPause(); | |
Log.e("log", "onpause"); | |
} | |
@Override | |
protected void onResume() { | |
super.onResume(); | |
Log.e("log", "onresume"); | |
} | |
@Override | |
protected void onStop() { | |
super.onStop(); | |
Log.e("log", "onstop"); | |
} | |
@Override | |
protected void onDestroy() { | |
super.onDestroy(); | |
Log.e("log", "ondestroy"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment