0

介護者の勤務表を取得するために使用するアプリがあります。介護者がログインすると、getRota というボタンをクリックできます。このボタンは Web サービスを呼び出し、日付がこのメソッドにも渡されるため、その日の勤務表を取得します。リストビューに勤務表が表示された勤務表ページに移動したら、次、前、日を選択する 3 つのボタンでアクティビティのオプションメニューをオーバーライドしました。最初の 2 つのボタンは、dateTime から 1 日を追加または 1 日削除し、それを呼び出し元のクラスに戻して、新しい日時で Web サービスを再度呼び出します。

勤務表を見ながら戻るキーを押すまで、これはすべて正常に機能します。戻るキーが押されると、getRota をクリックできる呼び出しアクティビティに戻ります。このメソッド内では、常に dateTime を今日に設定します。問題は、ユーザーが [勤務表を取得] をクリックしてから [次へ] をクリックし、次に [戻る] キーを押して [取得する] をクリックすると、リストビューに今日の日付が表示されるはずですが、翌日の勤務表が表示されることです。リストビューが現在の日付の勤務表で更新されていないようです。

ここにコードの一部を示します。必要に応じてさらに追加できます。

public class GetRota extends NfcBaseActivity implements OnItemClickListener {

    private static final String TAG = GetRota.class.getSimpleName();
    ListView listView;
    Intent intent;
    String callID;

    NfcScannerApplication nfcscannerapplication;
    ArrayList<?> array;
    String needName = "";
    MySimpleArrayAdapter arrayAdapter;
    private DatePicker dpResult;
    private int year;
    private int month;
    private int day;
    String statusField;
    static final int DATE_DIALOG_ID = 999;  
    TextView textViewDate; 

    @Override
    protected void onNewIntent(Intent intent) {
        setIntent(intent);
        super.onNewIntent(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.getrotalayout);
        setCurrentDateOnView();

        nfcscannerapplication = (NfcScannerApplication) getApplication();
        //set titlebar to carer's name
        Cursor cursorCarerName = nfcscannerapplication.loginValidate.queryAllFromCarer();
        cursorCarerName.moveToLast();
        String carerTitleName = cursorCarerName.getString(cursorCarerName.getColumnIndex(LoginValidate.C_CARER_FIRSTNAME)) + " " + cursorCarerName.getString(cursorCarerName.getColumnIndex(LoginValidate.C_CARER_LASTNAME)) ;
        setTitle(carerTitleName + " is currently logged in");
        listView = (ListView) findViewById(R.id.rotalist);
        textViewDate = (TextView)findViewById(R.id.textviewdate);
        Log.e(TAG, "textview = "+textViewDate);
        listView.setAdapter(arrayAdapter);
        listView.setOnItemClickListener(this);
    }// end of onCreate

    @Override
    public void onBackPressed() {
        Log.e(TAG, "onBack pressed globaldatetime = " + nfcscannerapplication.getglobalDateTime());
        super.onBackPressed();
    }

    @Override
    protected void onResume(){
        super.onResume();
        Log.e(TAG, "global date in onresume getrota = " + nfcscannerapplication.getglobalDateTime());
        array = (ArrayList<String[]>)getIntent().getBundleExtra("rotaArrayBundle").get("rotaArray");
        Log.e(TAG, "array size in onresume = " + array.size());
        if(array.size() == 0){
            //then needname must be out of range, toast user with no rota available
        DateTime unavailableDate = nfcscannerapplication.getglobalDateTime();
        DateTimeFormatter fmt2 = DateTimeFormat.forPattern("E dd MMM");
        String unavailStringDate = fmt2.print(unavailableDate);
        Log.e(TAG, "no rota!!!!!!!!!!!!!!!!");
        AlertDialog alertDialog = new AlertDialog.Builder(GetRota.this).create();
        alertDialog.setTitle("No Rota Available ");
        alertDialog.setMessage("Unable To View Rota For  " +"\n" + unavailStringDate);
        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {

                          onBackPressed();

                    } }); 

                alertDialog.show();

            }
            if (arrayAdapter == null){
                MySimpleArrayAdapter arrayAdapter = new MySimpleArrayAdapter(this, array);

                listView.setAdapter(arrayAdapter);
            }
        }


        private MySimpleArrayAdapter getListAdapter() {

            return arrayAdapter;
        }

        public void setCurrentDateOnView() {

            dpResult = (DatePicker) findViewById(R.id.datepicker1);

            final Calendar c = Calendar.getInstance();
            year = c.get(Calendar.YEAR);
            month = c.get(Calendar.MONTH);
            day = c.get(Calendar.DAY_OF_MONTH);


        }

        public boolean onCreateOptionsMenu(Menu menu) {
            MenuInflater inflater = getMenuInflater();
            inflater.inflate(R.menu.menurotadetails, menu);
            return true;
        }

        public boolean onOptionsItemSelected(MenuItem item) {
            switch (item.getItemId()) {


            case R.id.previous:


                DateTime dateTime = nfcscannerapplication.getglobalDateTime();
                DateTime dateTimeMinusOne = dateTime.minusDays(1);
                nfcscannerapplication.setGobalDateTime(dateTimeMinusOne);

                DateTimeFormatter fmt2 = DateTimeFormat.forPattern("d-MMM-Y");
                String previousDay = fmt2.print(dateTimeMinusOne);

                Intent i2 = new Intent(this, NfcscannerActivity.class);
                i2.putExtra("nextRota", previousDay);
                i2.setAction("NEXT_ROTA");
                startActivity(i2);

                return true;


            case R.id.next:

                DateTime dateTime2 = nfcscannerapplication.getglobalDateTime();
                DateTime dateTimePlusOne = dateTime2.plusDays(1);
                nfcscannerapplication.setGobalDateTime(dateTimePlusOne);

                DateTimeFormatter fmt = DateTimeFormat.forPattern("d-MMM-Y");
                String nextDay = fmt.print(dateTimePlusOne);

                Intent i = new Intent(this, NfcscannerActivity.class);
                i.putExtra("nextRota", nextDay);
                i.setAction("NEXT_ROTA");
                startActivity(i);

                return true;

            case R.id.today:
                setCurrentDateOnView();
                showDialog(DATE_DIALOG_ID);
                return true;

            default:

                return super.onOptionsItemSelected(item);
            }
        }


//adapter stuff...

.

呼び出しクラス(NfcscannerActivity)で

 Button getRota = (Button)findViewById(R.id.buttongetrota);

            getRota.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    Log.e(TAG, "onclicked getRota");






                    DateTime now = new DateTime();
                    nfcscannerapplication.setGobalDateTime(now);
                    Log.e(TAG, "now in getrota method in nfcact = "+ now);
                    DateTimeFormatter fmt = DateTimeFormat.forPattern("d-MMM-Y");
                    String formattedNow = fmt.print(now);
                    String[] params = new String[]{nfcscannerapplication.getCarerID(), formattedNow}; 
                    AsyncGetRota agr = new AsyncGetRota();
                    agr.execute(params); 

                     }

                }// end of onclick
            });


some intent processing......
if(intent.getAction().equalsIgnoreCase("NEXT_ROTA")){

            Log.e(TAG, "next rota action");
            String date = intent.getStringExtra("nextRota");

            getNextRota(date);
        } 



private void getNextRota(String stringExtra) {

    String[] params = new String[]{nfcscannerapplication.getCarerID(), stringExtra}; 
    AsyncGetRota agr = new AsyncGetRota();
    agr.execute(params);

    }



private class AsyncGetRota extends AsyncTask<String, Void, Void> {

        ProgressDialog progressDialog;
        Boolean isRotaArrayNull = false;

        @Override
        protected void onPreExecute()
        {
            progressDialog= ProgressDialog.show(NfcscannerActivity.this, 
                    "Connecting to Server"," retrieving rota...", true);


        };      


        @Override
        protected Void doInBackground(String... params) {

            try {
                Log.e(TAG, "inside doInBackground");

                Log.e(TAG, "now in doinbackground = " + params[1]);
                rotaArray = nfcscannerapplication.loginWebservice.getRota(params[0], params[1]);
                //nfcscannerapplication.loginWebservice.getRota(params[0], params[1]);

               if (rotaArray == null){
                   Log.e(TAG, "about to call onstart");
                   isRotaArrayNull = true;
               }

            } catch (Exception e) {



               e.printStackTrace();


            }
            return null;

        }

        @Override
        protected void onPostExecute(Void result)
        {
            super.onPostExecute(result);
            if(progressDialog != null)
            progressDialog.dismiss();

           if(isRotaArrayNull == false){

            Intent intent = new Intent(NfcscannerActivity.this,
                            GetRota.class);
             Bundle b = new Bundle();
             b.putSerializable("rotaArray", rotaArray);

             intent.putExtra("rotaArrayBundle", b);
             startActivity(intent);
        }else{

            AlertDialog alertDialog = new AlertDialog.Builder(NfcscannerActivity.this).create();
            alertDialog.setTitle("Signal Test");
            alertDialog.setMessage("No Phone Signal");

             alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {

                      onStart();
                } }); 



             alertDialog.show();

        }

        }


    }
4

1 に答える 1

0

解決しました。マニフェストに以下を追加しました

<activity
            android:name=".GetRota"
            android:launchMode="singleTask"
            android:screenOrientation="portrait" >
        </activity>

これが違いを生んだ理由は100%ではありませんが、singleTopをsingleTaskに変更すると解決しました

于 2012-10-22T12:47:21.410 に答える