代码清单10-7 使用newInstance(UUID)方法

package com.bignerdranch.android.criminallntent;

import android.content.Context;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import java.util.UUID;

public class CrimeActivity extends SingleFragmentActivity {
    private static final  String EXTRA_CRIME_ID=
            "com.bignerdranch.android.criminalintent.crime_id";

    public static Intent newIntent(Context packageContext,UUID crimeId){
        Intent intent=new Intent(packageContext,CrimeActivity.class);
        intent.putExtra(EXTRA_CRIME_ID,crimeId);
        return intent;
    }

    @Override
    protected Fragment createFragment(){
        UUID crimeId=(UUID)getIntent().getSerializableExtra(EXTRA_CRIME_ID);
        return CrimeFragment.newInstance(crimeId);
    }
}

你可能感兴趣的:(代码清单10-7 使用newInstance(UUID)方法)