Android 当mesg框退出时,它将返回到prevoius Activity
我从stack overflow中得到了一个代码,可以打开一个mesg框 当我在activty ActGetKey中调用mesga框时,按下exit(退出)按钮后,它会返回到starting activty MAIN(启动ACTIVITY主活动) mesg盒代码: 公共void msbox(字符串str、字符串str2) { AlertDialog.Builder dlgAlert=新建AlertDialog.Builder(此); dlgAlert.setTitle(str); dlgAlert.setMessage(str2); dlgAlert.setPositiveButton(“确定”,新的DialogInterface.OnClickListener(){ public void onClick(对话框接口对话框,int whichButton){ 完成(); } }); dlgAlert.setCancelable(真); dlgAlert.create().show(); } 主活动代码 公共类MainActivity扩展了AppCompatActivity{Android 当mesg框退出时,它将返回到prevoius Activity,android,Android,我从stack overflow中得到了一个代码,可以打开一个mesg框 当我在activty ActGetKey中调用mesga框时,按下exit(退出)按钮后,它会返回到starting activty MAIN(启动ACTIVITY主活动) mesg盒代码: 公共void msbox(字符串str、字符串str2) { AlertDialog.Builder dlgAlert=新建AlertDialog.Builder(此); dlgAlert.setTitle(str); dlgAler
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
keyDB db;
db = new keyDB(this);
db.setUp();
cPassKey mPassKey = new cPassKey("mysec","mypublic","myphase");
db.updateExchange("ted2", mPassKey);
Cursor cursor =db.selectKey("ted2");
// get keys in current pos of database
cPassKey mret=db.loadRecord(cursor);
String name;
Cursor test =db.selectKey("ted1");
name = test.getString(2);
name = test.getString(3);
cursor = db.selectRecords();
int id; String ted;
if (cursor != null)
{
do {
id = cursor.getInt(0);
ted = cursor.getString(1);
} while (cursor.moveToNext());
cursor.close();
}
}
public void sendMessage(View view) {
//Intent Intent=新Intent(这个,ActGetKey.class);
Intent Intent=新Intent(这个,ActGetKey.class);
星触觉(意向);
}
}
ActGetKey活动的代码
公共类ActGetKey扩展AppCompativeActivity实现AdapterView.OnItemSelectedListener{
String selItem=null;
long d=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_act_get_key);
keyDB db;
db= new keyDB(this);
Cursor cursor=db.selectRecords();
String ted="na";
int id=0;
if (cursor != null) {
// get keys in current pos of database
cPassKey mPassKey=db.loadRecord(cursor);
// displkay the keys on app
loadKeys(mPassKey);
// fill up spinner
Spinner spinner = (Spinner) findViewById(R.id.spinner2);
// Spinner click listener
spinner.setOnItemSelectedListener(this);
// Spinner Drop down elements
List<String> categories = new ArrayList<String>();
if (cursor != null) {
do {
id = cursor.getInt(0);
ted = cursor.getString(1);
categories.add(ted);
} while (cursor.moveToNext());
cursor.close();
}
// Creating adapter for spinner
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
spinner.setAdapter(dataAdapter);
// set selected item
spinner.setSelection(0);
}
}
public void Update3(View view)
String selItem=null;
long d=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_act_get_key);
keyDB db;
db= new keyDB(this);
Cursor cursor=db.selectRecords();
String ted="na";
int id=0;
if (cursor != null) {
// get keys in current pos of database
cPassKey mPassKey=db.loadRecord(cursor);
// displkay the keys on app
loadKeys(mPassKey);
// fill up spinner
Spinner spinner = (Spinner) findViewById(R.id.spinner2);
// Spinner click listener
spinner.setOnItemSelectedListener(this);
// Spinner Drop down elements
List<String> categories = new ArrayList<String>();
if (cursor != null) {
do {
id = cursor.getInt(0);
ted = cursor.getString(1);
categories.add(ted);
} while (cursor.moveToNext());
cursor.close();
}
// Creating adapter for spinner
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
spinner.setAdapter(dataAdapter);
// set selected item
spinner.setSelection(0);
}
}
public void Update3(View view)
String selItem=null;
长d=0;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u act\u get\u key);
keyDB;
db=新的keyDB(本);
Cursor Cursor=db.selectRecords();
字符串ted=“na”;
int id=0;
如果(光标!=null){
//获取数据库当前pos中的密钥
cPassKey mPassKey=db.loadRecord(游标);
//显示应用程序上的按键
加载键(mPassKey);
//加满旋转器
微调器微调器=(微调器)findViewById(R.id.spinner2);
//微调器单击侦听器
spinner.setOnItemSelectedListener(此);
//微调器下拉元素
列表类别=新建ArrayList();
如果(光标!=null){
做{
id=cursor.getInt(0);
ted=cursor.getString(1);
类别。添加(ted);
}while(cursor.moveToNext());
cursor.close();
}
//为微调器创建适配器
ArrayAdapter dataAdapter=新的ArrayAdapter(这是android.R.layout.simple\u微调器\u项,类别);
//下拉式布局样式-带单选按钮的列表视图
dataAdapter.setDropDownViewResource(android.R.layout.simple\u微调器\u下拉项);
//将数据适配器连接到微调器
spinner.setAdapter(dataAdapter);
//设置所选项目
微调器的选择(0);
}
}
公共无效更新3(视图)
{
d++;
编辑文本温度
temp = findViewById(R.id.publicKey);
String strPublicKey=(String)temp.getText().toString();
if (isValidString(strPublicKey))
{
msbox( getString(R.string.badtext), "Text for publick key is invalid");
return;
}
temp = findViewById(R.id.publicKey);
String strPrivetKey=(String)temp.getText().toString();
temp = findViewById(R.id.publicKey);
String strKeyPhrase=(String)temp.getText().toString();
// check for bad dada
}
boolean isValidString( String test)
{
if (test==null)
return false;
return true;
}
public void Update2(View view) {
// put keys in keyclass
msbox("kkk","kjjh");
if (true)
return;
keyDB db;
db= new keyDB(this);
cPassKey mPassKey = getKeys();
db.updateExchange(selItem, mPassKey);
// pus keyclass in data base
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// On selecting a spinner item
selItem = parent.getItemAtPosition(position).toString();
keyDB db;
db= new keyDB(this);
Cursor cursor =db.selectKey(selItem);
// get keys in current pos of database
cPassKey mPassKey=db.loadRecord(cursor);
// displkay the keys on app
loadKeys(mPassKey);
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
boolean loadKeys(cPassKey mPassKey)
{
EditText temp;
temp = findViewById(R.id.publicKey);
temp.setText(mPassKey.publickKey);
temp = findViewById(R.id.secretKey);
temp.setText(mPassKey.secretKey);
temp = findViewById(R.id.phraseKey);
temp.setText(mPassKey.phraseKey);
return true;
}
public void msbox(String str,String str2)
{
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
dlgAlert.setTitle(str);
dlgAlert.setMessage(str2);
dlgAlert.setPositiveButton("OK",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
finish();
}
});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
cPassKey getKeys()
{
EditText temp;
temp = findViewById(R.id.publicKey);
String strPublicKey= temp.getText().toString();
temp = findViewById(R.id.secretKey);
String StrSecretKey= temp.getText().toString();
temp = findViewById(R.id.phraseKey);
String StrPhraseKey= temp.getText().toString();
cPassKey mPassKey = new
cPassKey( StrSecretKey,strPublicKey, StrPhraseKey);
return mPassKey;
}
temp = findViewById(R.id.publicKey);
String strPublicKey=(String)temp.getText().toString();
if (isValidString(strPublicKey))
{
msbox( getString(R.string.badtext), "Text for publick key is invalid");
return;
}
temp = findViewById(R.id.publicKey);
String strPrivetKey=(String)temp.getText().toString();
temp = findViewById(R.id.publicKey);
String strKeyPhrase=(String)temp.getText().toString();
// check for bad dada
}
boolean isValidString( String test)
{
if (test==null)
return false;
return true;
}
public void Update2(View view) {
// put keys in keyclass
msbox("kkk","kjjh");
if (true)
return;
keyDB db;
db= new keyDB(this);
cPassKey mPassKey = getKeys();
db.updateExchange(selItem, mPassKey);
// pus keyclass in data base
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// On selecting a spinner item
selItem = parent.getItemAtPosition(position).toString();
keyDB db;
db= new keyDB(this);
Cursor cursor =db.selectKey(selItem);
// get keys in current pos of database
cPassKey mPassKey=db.loadRecord(cursor);
// displkay the keys on app
loadKeys(mPassKey);
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
boolean loadKeys(cPassKey mPassKey)
{
EditText temp;
temp = findViewById(R.id.publicKey);
temp.setText(mPassKey.publickKey);
temp = findViewById(R.id.secretKey);
temp.setText(mPassKey.secretKey);
temp = findViewById(R.id.phraseKey);
temp.setText(mPassKey.phraseKey);
return true;
}
public void msbox(String str,String str2)
{
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
dlgAlert.setTitle(str);
dlgAlert.setMessage(str2);
dlgAlert.setPositiveButton("OK",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
finish();
}
});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
cPassKey getKeys()
{
EditText temp;
temp = findViewById(R.id.publicKey);
String strPublicKey= temp.getText().toString();
temp = findViewById(R.id.secretKey);
String StrSecretKey= temp.getText().toString();
temp = findViewById(R.id.phraseKey);
String StrPhraseKey= temp.getText().toString();
cPassKey mPassKey = new
cPassKey( StrSecretKey,strPublicKey, StrPhraseKey);
return mPassKey;
}
temp=findviewbyd(R.id.publicKey);
字符串strPublicKey=(字符串)temp.getText().toString();
if(isValidString(strPublicey))
{
msbox(getString(R.string.badtext),“publick键的文本无效”);
返回;
}
temp=findViewById(R.id.publicKey);
String strPrivetKey=(String)temp.getText().toString();
temp=findViewById(R.id.publicKey);
字符串strKeyPhrase=(字符串)temp.getText().toString();
//检查坏爸爸
}
布尔值isValidString(字符串测试)
{
if(test==null)
返回false;
返回true;
}
公共无效更新2(视图){
//把钥匙放在钥匙课上
msbox(“kkk”、“kjjh”);
如果(真)
返回;
keyDB;
db=新的keyDB(本);
cPassKey mPassKey=getKeys();
数据库更新交换(selItem,mPassKey);
//数据库中的类
}
@凌驾
已选择公共视图(AdapterView父视图、视图视图、整型位置、长id){
//关于选择微调器项
selItem=parent.getItemAtPosition(position.toString();
keyDB;
db=新的keyDB(本);
Cursor Cursor=db.selectKey(选择项);
//获取数据库当前pos中的密钥
cPassKey mPassKey=db.loadRecord(游标);
//显示应用程序上的按键
加载键(mPassKey);
}
未选择公共无效(AdapterView arg0){
//TODO自动生成的方法存根
}
布尔加载键(cPassKey mPassKey)
{
编辑文本温度;
temp=findViewById(R.id.publicKey);
临时设置文本(mPassKey.publickKey);
temp=findViewById(R.id.secretKey);
临时设置文本(mPassKey.secretKey);
temp=findviewbyd(R.id.phraseKey);
临时设置文本(mPassKey.phraseKey);
返回true;
}
公共void msbox(字符串str、字符串str2)
{
AlertDialog.Builder dlgAlert=新建AlertDialog.Builder(此);
dlgAlert.setTitle(str);
dlgAlert.setMessage(str2);
dlgAlert.setPositiveButton(“确定”,新的DialogInterface.OnClickListener(){
public void onClick(对话框接口对话框,int whichButton){
完成();
}
});
dlgAlert.setCancelable(真);
dlgAlert.create().show();
}
cPassKey getKeys()
{
编辑文本温度;
temp=findViewById(R.id.publicKey);
字符串strPublicKey=temp.getText().toString();
temp=findViewById(R.id.secretKey);
字符串StrSecretKey=temp.getText().toString();
temp=findviewbyd(R.id.phraseKey);
字符串strprhasekey=temp.getText().toString();
cPassKey mPassKey=new
cPassKey(STRESCRETKEY、strPublicKey、STRPRASSEKEY);
返回mPassKey;
}
}
公共类ActGetKey扩展AppCompativeActivity实现AdapterView.OnItemSelectedListener{
String selItem=null;
long d=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_act_get_key);
keyDB db;
db= new keyDB(this);
Cursor cursor=db.selectRecords();
String ted="na";
int id=0;
if (cursor != null) {
// get keys in current pos of database
cPassKey mPassKey=db.loadRecord(cursor);
// displkay the keys on app
loadKeys(mPassKey);
// fill up spinner
Spinner spinner = (Spinner) findViewById(R.id.spinner2);
// Spinner click listener
spinner.setOnItemSelectedListener(this);
// Spinner Drop down elements
List<String> categories = new ArrayList<String>();
if (cursor != null) {
do {
id = cursor.getInt(0);
ted = cursor.getString(1);
categories.add(ted);
} while (cursor.moveToNext());
cursor.close();
}
// Creating adapter for spinner
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
spinner.setAdapter(dataAdapter);
// set selected item
spinner.setSelection(0);
}
}
public void Update3(View view)
String selItem=null;
long d=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_act_get_key);
keyDB db;
db= new keyDB(this);
Cursor cursor=db.selectRecords();
String ted="na";
int id=0;
if (cursor != null) {
// get keys in current pos of database
cPassKey mPassKey=db.loadRecord(cursor);
// displkay the keys on app
loadKeys(mPassKey);
// fill up spinner
Spinner spinner = (Spinner) findViewById(R.id.spinner2);
// Spinner click listener
spinner.setOnItemSelectedListener(this);
// Spinner Drop down elements
List<String> categories = new ArrayList<String>();
if (cursor != null) {
do {
id = cursor.getInt(0);
ted = cursor.getString(1);
categories.add(ted);
} while (cursor.moveToNext());
cursor.close();
}
// Creating adapter for spinner
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
spinner.setAdapter(dataAdapter);
// set selected item
spinner.setSelection(0);
}
}
public void Update3(View view)
String selItem=null;
长d=0;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u act\u get\u key);
keyDB;
db=新的keyDB(本);
Cursor Cursor=db.selectRecords();
字符串ted=“na”;
int id=0;
如果(光标!=null){
//获取数据库当前pos中的密钥
cPassKey mPassKey=db.loadRecord(游标);
//显示应用程序上的按键
加载键(mPassKey);
//加满旋转器
微调器微调器=(微调器)findViewById(R.id.spinner2);
//微调器单击侦听器
spinner.setOnItemSelectedListener(此);