(DatePickerActivity) >> to select type of note (SelectTypeActivity) >> to write the txt file (WriteNoteActivity). This is the process. But I have to change the intent SelectTypeActivity.class to WriteNoteActivity.class like this it will success, how can I no need to skip the SelectTypeActivity also able to do that ? =)
DatePickerActivity = create folder
public void onClick(DialogInterface dialog, int which) {
Environment.getExternalStorageDirectory();
String dateN = edit_date.getText().toString();
edit_date.setTypeface(edit_date.getTypeface(), Typeface.BOLD_ITALIC);
File folder = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/CalendarNote/" + dateN);
boolean success = true;
if (!folder.exists()) {
success = folder.mkdirs();
}
if (success) {
Toast.makeText(getBaseContext(), "You have successfully created." , Toast.LENGTH_LONG ).show();
Intent w = new Intent(DatePickerActivity.this, WriteNoteActivity.class);
w.putExtra("the_date", dateN);
startActivity(w);
} else {
Toast.makeText(getBaseContext(), "You have Failed to create." , Toast.LENGTH_LONG ).show();
}
}
})
WriteNoteActivity = create txt file
public void onClick(DialogInterface dialog, int which) {
String content = edit_content.getText().toString();
String title = edit_title.getText().toString();
//String dateN = edit_date.getText().toString();
boolean success = true;
try {
String dateN = getIntent().getStringExtra("the_date");
File sdCardDir = Environment.getExternalStorageDirectory();
File targetFile;
targetFile = new File(sdCardDir.getCanonicalPath()
+ "/CalendarNote/" + dateN );
// File file=new File(folderPath + "/"+title+".txt");
File file=new File(targetFile + "/"+title+".txt");
if(!targetFile.exists()){
success = targetFile.mkdir();
}
RandomAccessFile raf = new RandomAccessFile(file, "rw");
raf.seek(file.length());
raf.write(content.getBytes());
raf.close();
} catch (IOException e) {
e.printStackTrace();
}
if (success) {
Toast.makeText(getBaseContext(), "You have successfully created." , Toast.LENGTH_LONG ).show();
} else {
Toast.makeText(getBaseContext(), "You have Failed to create." , Toast.LENGTH_LONG ).show();
}
//Toast.makeText(getBaseContext(), "Note have successfully saved." , Toast.LENGTH_LONG ).show();
}
})
Any suggestion to not skip the SelectTypeActivity ? also able to getStringExtra from DatePickerActivity