警告消息:未使用字段CancelAnAlarmActivity.mDetailsButton的值

时间:2014-03-18 11:50:08

标签: sms alarmmanager

该程序正在我的模拟器和手机上运行,​​但我不明白为什么我会在ADT上获得此功能。我的代码有问题吗?请检查。我需要帮助。如果我删除此行,我的应用可能无法正常工作,根据我希望它如何工作。

这是我的一个java代码:

import java.util.List;

import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.app.PendingIntent;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;  <<-- This is where i get the warning message:"The import android.util.Log is never used"
import android.view.View;
import android.view.View.OnClickListener;  <<-- This is where i get the warning message:"The import android.util.Log is never used"
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;  <<-- This is where i get the warning message:"The import android.widget.Toast is never used"

public class CancelAnAlarmActivity extends ListActivity implements OnItemClickListener{
    private PendingIntentsDataSource mDatasource;
    private ListView mListView;
    private Button mDetailsButton;  <<-- This is where i get the warning message: The value of the field CancelAnAlarmActivity.mDetailsButton is not used
    private Button mCancelButton;  <<-- This is where i get the warning message:"The value of the field CancelAnAlarmActivity.mCancelButton is not used"
    private List<SMSSchedulerPendingIntent> mPendingIntentList;  <<-- This is where i get the warning message: "The value of the field CancelAnAlarmActivity.mPendingIntentList is not used"
    private String mNumberToSend;
    private String mReceiverName;
    private String mMessage;
    private String mFrequency;
    private static CancelAnAlarmActivity mCancelAlarmActivity;
    private int mIdOfAnPendingIntent;;

    //String newLine;
    String newL = System.getProperty("line.separator");
    @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mCancelAlarmActivity = this;
        mListView = getListView();

        //mDetailsButton = (Button)(findViewById(R.id.buttonDetails));
        mDatasource = new PendingIntentsDataSource(this);
        mDatasource.open();


        List<SMSSchedulerPendingIntent> values = mDatasource.getAllPendingIntents();

        final PendingIntentsArrayAdapter pendingIntentAdapter = new PendingIntentsArrayAdapter(this, R.layout.cancelanalarm, values);
        //setListAdapter(new PendingIntentsArrayAdapter(this, R.layout.cancelanalarm, values));
        setListAdapter(pendingIntentAdapter);
        //mDetailsButton = (Button)findViewById(R.id.buttonDetails);
        mPendingIntentList = pendingIntentAdapter.getPendingIntentList();

        mListView.setOnItemClickListener(this);

    }

    @Override
    public void onPause(){
        super.onPause();
        mDatasource.close();
        /*mEditTextMessage.setText("");
        mEditTextNumber.setText("");*/
    }
      @Override
    public void onResume(){
        super.onResume();
        mDatasource.open();
    }

    @Override
    public void onStart(){
        super.onStart();
        /*mEditTextMessage.setText("");
        mEditTextNumber.setText("");    */
        mDatasource.open();

    }
    @Override
    public void onStop(){
        super.onStop();
        /*mEditTextMessage.setText("");
        mEditTextNumber.setText("");    */  
        mDatasource.close();
    }

    @Override
    public void onDestroy(){
        super.onDestroy();
        /*mEditTextMessage.setText("");
        mEditTextNumber.setText("");*/
        mDatasource.close();
    }

    @Override
    public void onBackPressed(){
        mDatasource.close();
        Intent i = new Intent();
        i.setClassName("com.somitsolutions.android.smsscheduler", "com.somitsolutions.android.smsscheduler.SetuppageActivity");
        startActivity(i);
    }

    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        // TODO Auto-generated method stub
        //final String newLine = System.getProperty("line.seperator");
        SMSSchedulerPendingIntent selectedsmsSchedulerPendingIntent = (SMSSchedulerPendingIntent)(getListAdapter().getItem(arg2));
        mIdOfAnPendingIntent = (int) selectedsmsSchedulerPendingIntent.getId();
        mNumberToSend = selectedsmsSchedulerPendingIntent.getNumberToSend();
        mReceiverName = selectedsmsSchedulerPendingIntent.getReceiverName();
        mMessage = selectedsmsSchedulerPendingIntent.getMessage();
        mFrequency = selectedsmsSchedulerPendingIntent.getFrequency();
        String detailsTest = "Receiver's Number: "+ mNumberToSend + newL + "Receiver's Name: " + mReceiverName + newL + "Message: " + mMessage + newL + "Frequency: " + mFrequency;
        ShowCancelAlarmDetails(detailsTest);
        //mDetailsButton = (Button)(arg1.findViewById(R.id.buttonDetails));
        //mCancelButton = (Button)(arg1.findViewById(R.id.buttonCancel));
        /*mDetailsButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                String details = "Receiver's Number: "+ mNumberToSend + newL + "Receiver's Name: " + mReceiverName + newL + "Message: " + mMessage + newL + "Frequency: " + mFrequency;
                ShowCancelAlarmDetails(details);

            }
        });
        */
        /*mCancelButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                CancelAnAlarm(mIdOfAnPendingIntent);


            }
        });*/
    }

    public static CancelAnAlarmActivity getCancelAlarmActivity(){
        return mCancelAlarmActivity;
    }
    @SuppressWarnings("deprecation")
    public void  ShowCancelAlarmDetails(String message){
        //Toast.makeText(this, message, Toast.LENGTH_LONG).show();
        AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
        alertDialog.setTitle("Do you want to cancel this scheduled sms...");
        alertDialog.setMessage(message);
        //alertDialog.setCancelable(false);
        alertDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int which) {
              // TODO Add your code for the button here.
               CancelAnAlarm(mIdOfAnPendingIntent);
           }
        });
        alertDialog.setNegativeButton("No", new DialogInterface.OnClickListener(){
        public void onClick(DialogInterface dialog, int which) {
              // TODO Add your code for the button here.
           }
        });
        alertDialog.show();
    }

    public void CancelAnAlarm(int id){
        AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(getApplicationContext().ALARM_SERVICE);
        Intent i = new Intent(getApplicationContext(), SendSMSAlarmService.class);
        PendingIntent pi = PendingIntent.getService(getApplicationContext(), id, i, PendingIntent.FLAG_UPDATE_CURRENT);
        am.cancel(pi);
        mDatasource.deletePendingIntent(id);
        Intent refresh = new Intent();
        refresh.setClassName("com.somitsolutions.android.smsscheduler", "com.somitsolutions.android.smsscheduler.CancelAnAlarmActivity");
        startActivity(refresh);
    }

    public void DeleteAnForOnceAlarmEntryFromDatabase(int id){
        mDatasource.deletePendingIntent(id);
        /*Intent refresh = new Intent();
        refresh.setClassName("com.somitsolutions.android.smsscheduler", "com.somitsolutions.android.smsscheduler.CancelAnAlarmActivity");
        startActivity(refresh);*/
    }
}

我在其他java代码中收到了相同类型的警告消息。

1 个答案:

答案 0 :(得分:1)

您已将mDetailsButton声明为字段变量,但您注释了包含此变量的所有部分。这就是你收到未使用变量警告的原因。