2013-05-15 81 views
0

我試圖將值傳遞給新的活動,但無法讀取新活動的值。android將值傳遞給另一個活動,但無法讀取

這裏是我的代碼,

Intent myIntent = new Intent(Photo2Activity.this, MainActivity.class); 

myIntent.putExtra("image1", image1); 
myIntent.putExtra("image2", image2); 
myIntent.putExtra("image3", image3); 

myIntent.putExtra("konteyner_no", _txt_konteyner_id.getText().toString()); 
myIntent.putExtra("mahalle", _txt_mahalle.getText().toString()); 
myIntent.putExtra("sokak", _txt_sokak.getText().toString()); 

myIntent.putExtra("konteyner_temizmi", _check_konteyner_temizmi.isChecked()); 
myIntent.putExtra("yaninda_cop_varmi", _check_yaninda_cop_varmi.isChecked()); 
myIntent.putExtra("aralarinda_cop_varmi", _check_aralarinda_cop_vardi.isChecked()); 
myIntent.putExtra("zamansiz_cop_varmi", _check_zamansiz_cop_vardi.isChecked()); 
myIntent.putExtra("cop_obekleri_vardi", _check_cop_obekleri_vardi.isChecked()); 

myIntent.putExtra("note", _txt_note.getText().toString()); 

startActivity(myIntent); 

我如何從新的活動(MainActivity)讀?

+0

如果它的基本類型,你想通過然後檢查此鏈接http://stackoverflow.com/questions/15859445/how-do-you-pass-a-string-from-one-activity-to -another/15859488#15859488。你傳遞的圖像? – Raghunandan

+0

我有3位圖,我發送 –

+0

位圖http://stackoverflow.com/questions/2459524/how-can-i-pass-a-bitmap-object-from-one-activity-to-another – Capitan

回答

2

轉換位圖字節數組: -

Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); 
ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); 
byte[] byteArray = stream.toByteArray(); 

通行證字節數組到意圖: - 從捆綁

Intent intent = new Intent(MainActivity.this, NextActivity.class); 
intent.putExtra("picture", byteArray); 
startActivity(intent); 

獲取字節數組,轉換成位圖圖像: -

Bundle extras = getIntent().getExtras(); 
byte[] byteArray = extras.getByteArray("picture"); 
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length); 
ImageView image = (ImageView) findViewById(R.id.imageView1); 
image.setImageBitmap(bmp); 

傳遞原始類型檢查下面的鏈接

How do you pass a string from one activity to another?

+0

我需要將這些圖像和其他圖像傳遞給web服務。將它發送到bytearray更好嗎? –

+0

你是標題說在活動之間傳遞位圖(標題中的值)。沒有提及web服務。答案是在活動之間傳遞位圖。無論如何,您應該使用http post請求將圖像發送到服務器 – Raghunandan

+0

,謝謝.. –

相關問題