번들을 사용하여 TIME의 인스턴스 (객체)를 전달하는 방법 ???번들을 통해 TIME 객체 전달
은 간단한 질문이 될 수 있습니다,하지만 난
DATE date=new DATE();
번들을 사용하여 TIME의 인스턴스 (객체)를 전달하는 방법 ???번들을 통해 TIME 객체 전달
은 간단한 질문이 될 수 있습니다,하지만 난
DATE date=new DATE();
이 코드는 대략 메모리에서 쓴 이후입니다. ActivityB의에서 onCreate에서 다음
Intent mIntent = new Intent(ActivityA.this, ActivityB.class);
mIntent.putLong(KEY, getTimeMilliseconds());
startactivity(mIntent);
:
Bundle mBundle = getItent().getExtras();
Long time = mBundle.getLong(KEY);
참고 : putLong/getLong 여러 String 형, INT에 적용 할 수있는
...
당신이 원하는 경우 사용자 지정 개체에 적용하려면 해당 개체를 만들어야합니다. Parcelable을 구현합니다.
가 번들 예를 들어, 당신의 날짜를 나타내는 긴 값을 전달 ... 정확한 답이 필요 long time = new Date(). getTime();
날짜는 직렬화, 그래서 당신은 get/putSerializable
를 사용할 수 있습니다
MyFragment fragment = new MyFragment();
Bundle bundle = new Bundle();
bundle.putSerializable(MyFragment.DATE_KEY, new Date());
fragment.setArguments(bundle);
MyFragment
에서 :
public void onViewStateRestored(Bundle savedInstanceState) {
super.onViewStateRestored(savedInstanceState);
Bundle bundle = savedInstanceState != null ? savedInstanceState : getArguments();
Date startTime = (Date) bundle.getSerializable(MyFragment.DATE_KEY);
this.time = startTime;
}
public void onSaveInstanceState(Bundle bundle) {
super.onSaveInstanceState(bundle);
bundle.putSerializable(MyFragment.DATE_KEY, this.time);
}
내가 다른 클래스에 전달해야하지만이 아닌 활동 ... 할 수있는 사람하시기 바랍니다 구체화 되느냐? ??? – subrussn90
parcelable [Parcelable Example] (http://stackoverflow.com/a/8653518/794291)을 구현하려면 개체가 필요합니다. 객체가 그것을 수행하면 번들을 사용하여 객체를 전송할 수 있습니다. – Rick