0

我正在尝试从服务中获取数据并将其传递给通知。但是当我在真实设备上运行它时,它只是在通知中显示“已向您发送朋友请求”,数据消失了。然后我在 logcat 中发现了问题输出如下所示:

日志输出:

   11-19 23:12:18.344: D/dataServices1(17701): admin*admin*
   11-19 23:12:18.344: D/dataServices2(17701): [Ljava.lang.String;@40d9f0d8
   11-19 23:12:18.344: D/dataServices3(17701): nulladmin,admin,
   11-19 23:12:18.344: D/dataServices3(17701): ,

admin*admin* < 它在这里发送了两个数据。

所以我的问题是如何将它从“[Ljava.lang.String;@40da8e78”转换为“admin”以及为什么它只显示“[Ljava.lang.String;@40da8e78”而不是两次?像 [Ljava.lang.String;@40da8e78 [Ljava.lang.String;@40da8e78...为什么“str”(dataServices3) 输出显示为这样?

这是代码:

   String datapassed; 
   String str = "";
   String[] data;
   int dlength;

   public void onReceive(Context context, Intent intent) {
    datapassed = intent.getStringExtra("DATAPASSED");
    if(datapassed.length()>0){
    //update from here
        data = datapassed.split("[*]");
        dlength = data.length;

        for(int i=0;i<dlength;i++){
            if(i==dlength-1){
                str += String.valueOf(data[i]);                 
            }else{
                str += String.valueOf(data[i]) + ",";
            }
            Log.d("dataServices3",str);
            displayNotification();

        }
            str = "";
        Log.d("dataServices1",datapassed);
        Log.d("dataServices2",data.toString());
     //to here
    }
    }
    };

    protected void displayNotification(){
        Intent i = new Intent(this,NotificationView.class);
        i.putExtra("notification", notification);

        PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0);

        NotificationManager mnotis =(NotificationManager)getSystemService(NOTIFICATION_SERVICE);

        Notification notis = new Notification(R.drawable.ic_launcher,"Reminder:You have " + dlength + " new friend request",System.currentTimeMillis());
        notis.setLatestEventInfo(this,"Friend Request", str + "has sent you a friend request",pi);
        notis.vibrate = new long[]{100,250,100,500};
        mnotis.notify(0, notis);
    }

这是运行后的 logcat 错误输出:

 11-19 23:28:46.388: E/ExternalAccountType(11253): Unsupported attribute readOnly
 11-19 23:28:46.648: E/ExternalAccountType(11253): Unsupported attribute readOnly
 11-19 23:28:57.218: E/MediaProvider(19282): invalid album art, error creating album thumb file
4

1 回答 1

0

也许我没有理解正确,您在数组中有一个对象,并且想要转换为它是类型化类,在这种情况下它是admin. 如果您没有像字符串array[0] = obj.toString()一样保留在数组中,则可以将对象转换如下。

admin adminFromData = null;
if (obj.getClass().isInstance(admin.class)) 
{
    admin = (admin)obj;
}
 //what ever you want with the admin object.
于 2012-11-19T15:43:11.897 回答