2016-09-06 112 views
0

我想在兩個活動之間傳遞一個字符串,但是當我收到字符串時,我得到一個空值。 我在其他活動中使用相同的代碼並且完美地工作。任何建議?bundle.getString()返回空值

第一項活動:

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.activity_post); 





    Glide.with(PostCarrete.this).load(foto) 
      .centerCrop() 
      .into(imagen); 

    next = (ImageView) findViewById(R.id.next) ; 
    next.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 

      Intent intent = new Intent(PostCarrete.this, Compartir.class); 
      intent.putExtra("foton",foto); 
      startActivity(intent); 

     } 
    }); 
} 

次活動:

Bundle bundle = getIntent().getExtras(); 
    foto = bundle.getString("foton"); 

這裏包的價值是零,所以照片太

+0

爲什麼你寫Bundle bundle = getIntent()。getExtras(); foto = bundle.getString(「foto」);在第一個活動?在哪個活動中bundle的值爲null? –

+0

你在哪裏存儲該字符串,在哪個活動? – Stanojkovic

+0

也許'getIntent()。getStringExtra(「foton」)'? – Gudin

回答

0

我覺得應該是:

String foto = getIntent().getStringExtra("foton"); 

因爲y ou正在發送作爲額外