使用內部存儲單獨保存對象或其領域。
public void writeToInternalStorage(String fileName,String userName)
{
try{
String endOfLine = System.getProperty("line.separator");
StringBuffer buffer = new StringBuffer();
FileOutputStream fos = openFileOutput(fileName, Context.MODE_PRIVATE); //// MODE_PRIVATE will create the file (or replace a file of the same name) and make it private to your application. Other modes available are: MODE_APPEND, MODE_WORLD_READABLE, and MODE_WORLD_WRITEABLE.
buffer.append(userName.toString() + endOfLine);
fos.write(buffer.toString().getBytes());
Log.v(TAG, "writeFileToInternalStorage complete.. " + buffer.toString());
// writer.write(userName);
fos.close();
}
catch(Exception e)
{
Log.v(TAG, "Error: " + e.getMessage());
ExceptionNotificationMessage("writeToInternalStorage() Error: " + e.getMessage());
}
}
public String readFromInternalStorage(String fileName)
{
try{
File file = this.getFileStreamPath(fileName);
if(file.exists() == true)
{
Log.v(TAG, "readFileFromInternalStorage File found...");
FileInputStream fis = openFileInput(fileName);
StringBuilder buffer = new StringBuilder();
int ch;
while((ch = fis.read()) != -1){
buffer.append((char)ch);
}
Log.v(TAG, "readFileFromInternalStorage complete.. " + buffer.toString());
fis.close();
return buffer.toString();
}
}
catch(Exception e)
{
Log.v(TAG, "Error: " + e.getMessage());
ExceptionNotificationMessage("readFromInternalStorage() Error: " + e.getMessage());
}
return "";
}
感謝您確認我的懷疑。我不知道START_REDLIVER_INTENT(必須掩蓋部分文檔)。 – adstro 2010-10-19 01:18:34
感謝的人,我被這個錯誤了將近一個月落馬......終於找到了Android操作系統殺死服務... – 2015-09-03 17:37:52
尼斯。我從來不知道'START_REDELIVER_INTENT',它肯定派上了用場@Falmarri – 2016-07-31 00:14:37