我正在重新提出这个问题:
我想在alertDialog中按“OK”时重新启动我的应用程序。但是,当我按下按钮时,我正在“完成操作使用”屏幕,如何启动我的应用程序而不必转到“完成操作...”?
这是重启应用程序的正确方法吗?
P.S。我需要重新启动应用程序,因为最初当应用程序启动时,列表从本地数据库显示,然后从服务器获取新数据并更新本地数据库后,我无法显示更新列表。它重新启动应用程序后工作。
调用startActivity的代码:
Toast.makeText(mContext,“Reading complete”,Toast.LENGTH_SHORT).show();
AlertDialog.Builder clickAlert = new AlertDialog.Builder(mContext);
clickAlert.setMessage("Database has been updated, please restart application to load new data. ");
clickAlert.setPositiveButton("Restart", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Intent i = new Intent("android.intent.action.MAIN");
mContext.startActivity(i);
}
});
clickAlert.create().show();
我有一个从String适配器填充的listFragment,这个字符串是从一个从服务器返回数据的方法填充的。我需要重新填充这份清单。 代码:
//获取包含商店列表的游标
Cursor curStoreList = mDbHelper.getStoreList();
String[] StoreList = new String[curStoreList.getCount()];
int i = 0;
// Store returned items in StoreList[]
while (curStoreList.moveToNext()) {
String storeName = curStoreList.getString(0);
StoreList[i] = storeName;
i++;
}
// Create an adapter with list of stores and populate the list with
// values
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, StoreList);
setListAdapter(adapter);
答案 0 :(得分:2)
实际上,
android.intent.action.MAIN
是Intent Action Name,不是任何Activity名称。
您必须使用要启动的活动名称而不是它..
等
Intent intent = new Intent(<Current_Activity>.this, <Starting_Activity>.class);
<强>更新强>
您想要通过android.intent.action.MAIN
实现的目标是Android中所有应用程序的常规操作名称。
如果要使用Intent Action Name启动Activity,则必须在应用程序的Manifest文件的Activity Tag中定义自己的Intent Action Name。
看看这个SO问题How can I start MAIN activity with the help of <intent-filter>?
答案 1 :(得分:0)
更改此意图
Intent i = new Intent("android.intent.action.MAIN");
类似
Intent mainIntent = new Intent(crntactivity.this, classuwanttogo.class);