Commits

Michael Ma committed d5c6ba0

编辑 新建笔记 Activity销毁修复

Comments (0)

Files changed (3)

Project/src/com/noodle/note/activity/EditNoteActivity.java

 import android.view.View.OnClickListener;
 import android.widget.Button;
 import android.widget.EditText;
+
 import com.noodle.note.R;
 
 /**
  * @author TonySeek
  * 
  */
-public class EditNoteActivity extends Activity {
-	public final static String SAVE_BUNDLE = "EDIT_NOTE_ACTIVITY_BUNDLE";
-	
+public class EditNoteActivity extends Activity{
+
 	/**
 	 * 工作模式
 	 */
 			Bundle extras = new Bundle();
 			workMode.saveArticle(extras);
 			// 记录 bundle 到 Intent
-			intent.putExtra(SAVE_BUNDLE, extras);
+			intent.putExtras(extras);
 			// 跳转 Activity
 			startActivity(intent);
+			EditNoteActivity.this.finish();
 		}
 	};
 
 	private void initWorkMode() {
 		Intent intent = getIntent();
 		Bundle extras = intent.getExtras();
-		Integer savedNoteId = (Integer) extras.get("noteId");
 		
 		// 设置工作模式
-		if (savedNoteId == null) {
+		if (extras == null) {
 			workMode = EditNoteWorkMode.getNewEditMode();
 		} else {
+			int savedNoteId = extras.getInt("noteId");
 			workMode = EditNoteWorkMode.getExistedEditMode(savedNoteId);
 		}
 

Project/src/com/noodle/note/activity/EditNoteWorkMode.java

 	 */
 	public static EditNoteWorkMode getEditMode(Bundle extras) {
 		String type = extras.getString(CLASS_TYPE);
-		if (type == NewEditMode.class.toString()) {
+		if (NewEditMode.class.getName().equals(type)) {
 			return new NewEditMode(extras);
-		} else if (type == ExistedEditMode.class.toString()) {
+		} else if (ExistedEditMode.class.getName().equals(type)) {
 			return new ExistedEditMode(extras);
 		} else {
 			throw new RuntimeException("无效的 EditNoteWorkMode");
 	 * @param extras
 	 */
 	public void saveArticle(Bundle extras) {
-		extras.putString(CLASS_TYPE, this.getClass().toString());
+		extras.putString(CLASS_TYPE, this.getClass().getName());
 	}
 }
 

Project/src/com/noodle/note/activity/SavingNoteActivity.java

 	 * 保存笔记
 	 */
 	private void saveNote(String title, String author, String[] tags) {
-		Toast tips = new Toast(this);
-
 		// 验证输入
 		if (title == null || title.trim().length() == 0) {
-			tips.setText("请输入标题");
-			tips.show();
+			Toast.makeText(this, "请输入标题", Toast.LENGTH_SHORT).show();
+			return;
 		} else if (author == null || author.trim().length() == 0) {
-			tips.setText("请输入作者");
-			tips.show();
+			Toast.makeText(this, "请输入作者", Toast.LENGTH_SHORT).show();
+			return;
 		}
-
 		// TODO: 处理标签 
 
 		note.setTitle(title.trim());
 		session.flush();
 
 		// 提示
-		tips.setText("保存成功");
-		tips.show();
+		Toast.makeText(this, "保存成功", Toast.LENGTH_SHORT).show();
 		
 		// 跳转
 		Intent intent = new Intent(this, NoteReadActivity.class);
 		intent.putExtra("id", note.getId());
 		startActivity(intent);
+		this.finish();
 	}
+	
 }