I want to pass a string from one activity to another, in one of them I wrote
public void pdfView(File f) {
// f is: /data/data/com.example.iktabClasses/files/fileName.pdf
Intent intent = new Intent(getApplicationContext(),NewPdfActivity.class);
intent.putExtra("filename", f);
startActivity(intent);
}
and in the other Activity I wrote:
Bundle b=getIntent().getExtras();
if (b != null) {
filename = getIntent().getStringExtra("filename");
System.out.println("filename: "+filename);
}
but filename always returns as 'null'. How to solve this? Thanks in advance. //////////////////
I made it as
Intent intent;
Bundle b = new Bundle();
b.putString("filename", f.toString());
intent = new Intent(getApplicationContext(),NewPdfActivity.class);
intent.putExtras(b);
startActivity(intent);
and Now it work
try this way
Intent intent = new Intent(first.this, second.class);
Bundle bundle = new Bundle();
bundle.putInt("index", index);
intent.putExtras(bundle);startActivity(intent);
then get it as
Bundle b = getIntent().getExtras();
int index = b.getInt("index");
in your other activity, instead of using
filename = getIntent().getStringExtra("filename");
try using
filename = b.getString("filename");
That should solve your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With