Android多进程IPC失败

时间:2017-05-26 07:10:31

标签: android ipc multiprocess

无法从应用中获取log 这是我的代码:

------------------ -------------的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>

            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <activity android:name=".SecondActivity"
        android:process=":hello2">
    </activity>
</application>

------------------- ------------ SecondActivity.java

public class SecondActivity extends AppCompatActivity {
protected File mF;

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

    mF = new File(getFilesDir(), "ss");
}

public void write(View view) {
    Storage storage = new Storage("Hello3", 4);

    try {
        ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(mF));
        outputStream.writeObject(storage);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

public void read(View view) {
    try {
        ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(mF));
        Storage storage = (Storage) inputStream.readObject();
        Log.d("Syuu", storage.name);//Error here.no log output
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}

}

-------------------- Storage.java ----------------

public class Storage implements Serializable {
public String name;
public int id;

public Storage(String name, int id) {
    this.name = name;
    this.id = id;
  }
}

0 个答案:

没有答案