본문 바로가기

개발도구/aOS - 안드로이드 개발

[안드로이드] intent get 값 받기 , send 보내기 관해..

인텐트 를 받아오는 지 안 받아 오는지에 따라 값을 설정하도록 하기 위해
아내 if 절을 보면 쉽게 알수 있다.
단! 인텐드에서 값을 받아 오지도 않고 무십코 Log.v 하면 null 값이라도 에러가 나니 주의 바란다. 
      
값 받기
                        String category ="";
String type="";
Intent intent = getIntent();

if (intent != null) {
Bundle b = intent.getExtras();
if (b == null) {
type ="MenuMt";
} else {
num = b.getString("num");
category = b.getString("category");
type = b.getString("type");
// Log.v("MTcategory", category);
}
}
       
         값 보내기
Intent i = new Intent(context, MenuMt.class);
//i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("type", "MenuMt");
i.putExtra("num", "11111111111111"); 
                                context.startActivity(i);