2

私は 2 つのアクティビティを持っています: MainActivityはNewReminderActivityを開始します。新しいリマインダーが作成されると、最初のリマインダーに通知されます。したがって、インターフェイスOnEventAddedListenerを実装します。

MainActivityをインテントに追加するためにシリアル化を使用する必要がありますか、それともより良い解決策がありますか? シリアライゼーションを使用してこれを達成する例を見たことがありません。通信のために、あるアクティビティから別のアクティビティにインターフェイスを渡すことは非常に一般的です。

public class MainActivity extends Activity implements OnEventAddedListener {

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        if(item.getItemId() == R.id.action_addReminder)
        {
             // NewReminderActivity c = new NewReminderActivity(this);
             // Intent intent = new Intent(this, c.getClass()); // this won't work

             Intent intent = new Intent(this, NewReminderActivity.class);
             startActivity(intent);
             return true;
        } else {
             return super.onOptionsItemSelected(item);
       }
   }
}
4

1 に答える 1