1

私はこの質問を再投稿しています:

alertDialogで「OK」を押したときにアプリケーションを再起動したい。しかし、ボタンを押すと「Complete Action USing」画面が表示されますが、「Complete Action ..」に移動せずにアプリケーションを起動するにはどうすればよいですか?

そして、それはアプリケーションを再起動する正しい方法ですか?

PSアプリケーションを起動すると、最初はローカルデータベースからリストが表示され、サーバーから新しいデータを取得してローカルデータベースを更新した後、更新されたリストを表示できないため、アプリケーションを再起動する必要があります。アプリを再起動した後に動作します。

startActivityを呼び出すためのコード:

Toast.makeText(mContext、 "読み取り完了"、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();

文字列アダプタから入力される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);
4

2 に答える 2

2

実際、

android.intent.action.MAIN

はインテントアクション名であり、アクティビティ名ではありません。

代わりに、開始するアクティビティ名を使用する必要があります。

お気に入り、

Intent intent = new Intent(<Current_Activity>.this, <Starting_Activity>.class);

アップデート:

そして、あなたが達成したいandroid.intent.action.MAINのは、Androidのすべてのアプリケーションの一般的なアクション名です。

インテントアクション名を使用してアクティビティを開始する場合は、アプリケーションのマニフェストファイルのアクティビティタグで独自のインテントアクション名を定義する必要があります。

このSOの質問を見てください<intent-filter>を使用してMAINアクティビティを開始するにはどうすればよいですか?

于 2012-08-23T07:06:39.853 に答える
0

この意図を変える

     Intent i = new Intent("android.intent.action.MAIN");

のような何かに

         Intent mainIntent = new Intent(crntactivity.this, classuwanttogo.class);
于 2012-08-23T07:03:04.053 に答える