0

尝试使用以下方法在活动和服务之间传递数据时出现以下错误,我真的不知道为什么:

数据计数实用程序:

public class DataCountUtilities {

    //swap the content of a string by switching place
    //each pair of consecutive characters
    //If string length is odd last character is left in place
    public String swappedMdn(Context ctx){ 
        TelephonyManager tm = (TelephonyManager)ctx.getSystemService(Context.TELEPHONY_SERVICE);
        //Extract the phone number from the TelephonyManager instance
        String mdn = tm.getLine1Number();
        //Insure MDN is 10 characters
        if (mdn.length() < 10 || mdn == null) mdn ="0000000000";
        //Extract last 10 digits of MDN
        if (mdn.length() > 10) mdn = mdn.substring(mdn.length() - 10, mdn.length()); 
        char data[] = mdn.toCharArray();
        char digit;
        for (int index = 0; index < mdn.length() - (mdn.length())%2; index+=2){
            digit = data[index];
            data[index] = data[index+1];
            data[index+1] = digit;


            Intent i = new Intent(DataCountUtilities.this, DataCountService.class);  
            i.putExtra("key", mdn);  
            startActivity(i);  

                }

        return String.valueOf(data); 

}

    private void startActivity(Intent i) {
        // TODO Auto-generated method stub

    }}
4

1 回答 1

1

Intent期望 aContext作为第一个参数。

换行

Intent i = new Intent(DataCountUtilities.this, DataCountService.class);

Intent i = new Intent(ctx, DataCountService.class);
于 2013-06-24T18:28:45.670 回答