小编arm*_*adi的帖子

如何序列化对象的ArrayList?

我想序列化Item的arraylist 但它不起作用....

我的Item类扩展了Stuff类并且有一些子类.

我的所有类都实现了Serilalizable.

我有这个部分:

try{
// Serialize data object to a file
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("MyData.ser"));
out.writeObject(myData);
out.close();

// Serialize data object to a byte array
ByteArrayOutputStream bos = new ByteArrayOutputStream() ;
out = new ObjectOutputStream(bos) ;
out.writeObject(myData);
out.close();

// Get the bytes of the serialized object
byte[] buf = bos.toByteArray();
} catch (IOException e) {
}
Run Code Online (Sandbox Code Playgroud)

我的课程 :

public class Stuff implements Serializeable{
....
some protected fields
. …
Run Code Online (Sandbox Code Playgroud)

java serialization arraylist subclass extend

2
推荐指数
1
解决办法
2万
查看次数

单击通知android启动活动

我点击通知时开始活动有问题...

public class MyNotification extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    // Toast.makeText(context, "notification", 25).show();

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
            context).setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("Test Notification")
            .setContentText("This is test notification ");
    Intent myIntent = new Intent(context, MainActivity.class);
    PendingIntent intent2 = PendingIntent.getBroadcast(context, 1,
            myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    notificationBuilder.setContentIntent(intent2);
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    mNotificationManager.notify(1, notificationBuilder.build());
}

}
Run Code Online (Sandbox Code Playgroud)

怎么了 ???

notifications android android-intent start-activity

0
推荐指数
1
解决办法
9069
查看次数