1

활동간에 드로어 블을 전달하려고합니다. 나는 alertdialog에서 drawable resourceID를 가져 와서 그 값을 다른 액티비티로 Int로 전달할 수 있는지 확신 할 수 없다.활동간에 드로어 블 통과하기

드로어 블을 비트 맵으로 변경하는 방법을 살펴본 결과, getResources(). getIdentifier()를 사용해 보았지만 잘못 사용했을 수도 있습니다.

나는 (번들)

public class CreateActivity extends Activity implements OnClickListener { 

EditText etTitle; 
Button btDate; 
Button btTime; 
Button btPic; 


@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_create); 
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 

    //onclicklistener 
    findViewById(R.id.btn_confirm).setOnClickListener(this); 
    findViewById(R.id.btn_back).setOnClickListener(this); 

    etTitle = (EditText) findViewById(R.id.editTextTitle); 
    btDate = (Button) findViewById(R.id.btn_date); 
    btTime = (Button) findViewById(R.id.btn_time); 
    btPic = (Button) findViewById(R.id.btn_picture); 

} 

// Will be called via the onClick attribute 
// of the buttons in main.xml 
public void onClick(View view) { 
    switch (view.getId()) { 
    case R.id.btn_confirm: 
     String title = etTitle.getText().toString(); 
     String time = btTime.getText().toString(); 
     String date = btDate.getText().toString(); 

     Drawable drawable = getResources().getDrawable(R.id.btn_picture); 

     Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap(); 

     Log.e("LOG", title); 
     Log.e("LOG", time); 
     Log.e("LOG", date); 

     Bundle newBundle = new Bundle(); 
     newBundle.putString("TITLE", title); 
     newBundle.putString("TIME", time); 
     newBundle.putString("DATE", date); 

     //Trying to pass a drawable from one activity to another 
     newBundle.putParcelable("BITMAP", bitmap); 

     Intent intent = new Intent(this, MainActivity.class); 
     intent.putExtras(newBundle); 

     setResult(RESULT_OK, intent); 

     finish(); 

     break; 

    case R.id.btn_back: 
     finish(); 
     break; 
    } 

} 

public void showTimePickerDialog(View v) { 
    DialogFragment newFragment = new TimePickerFragment(); 
    newFragment.show(getFragmentManager(), "timePicker"); 
} 

public void showDatePickerDialog(View v) { 
    DialogFragment newFragment = new DatePickerFragment(); 
    newFragment.show(getFragmentManager(), "datePicker"); 
} 

public void showPicturePickerDialog(View v) { 
    DialogFragment newFragment = new PicturePickerFragment(); 
    newFragment.show(getFragmentManager(), "picturePicker"); 
} 

} .putExtras를 사용하여 활동 사이의 당김을 통과 무엇을해야

답변

2

정수를 나타내는 식별자를 전달하는 것이 좋습니다. 다음 활동에서 필요에 따라 드로어 블을 재구성하십시오.

intent.putIntExtra(DRAWABLE_KEY, R.id.your_drawable_id); 
0

만큼 같은 APK 내부의 체류가, 난 그냥 전송하는 것 같은 모든 drawable (R.id.btn_picture)의 ID는 int로, 모든 서비스/활동이 자원을 확보 할 수 있기 때문입니다.