Share Coding

Tutorials, Problems, Stuffs …

Tag Archives: intent

Android Pass object between Intent

1. First of all, your Object class must be

implements Serializable

2. Package your parameter into a Bundle

User user1= new User("user1", "M");
Bundle bundle = new Bundle();
bundle.putSerializable("USER", user1);

Read more of this post

Advertisements

Open PDF file at Inent

// Check if file download state = complete && file exists
if (property.isTutorDLComplete() && tutorFile.exists()) {
    try {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(tutorFile), "application/pdf");
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        startActivity(intent);
    } catch (ActivityNotFoundException activityNotFoundException) {
        // Error occur when there are no pdf reader
        activityNotFoundException.printStackTrace();
        // Ask for download PDF Reader
        showSimpleConfirmDialog(R.string.ask_dl_pdfreader, ACTION_DL_PDF_READER);
    }
} else {
    showSimpleAlertDialog(R.string.error_tutor);
}
// After confirm dialog, this function will be executed
private void goToDLPDFReader(){
    // Download adobe reader
    String url = "https://play.google.com/store/apps/details?id=com.adobe.reader";
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(url));
    i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    startActivity(i);
}