我收到许多用户之前询问的错误。我不明白这一点,用前面的解释无法解决我的问题。
这是主要活动:
public class MainActivity extends Activity {
static final String STATE_BLOC_NOTES = "STATE_BLOC_NOTES";
static final String STATE_RECHERCHE = "RECHERCHE";
BlocNotes monBlocNotes;
EditText editTexteRechercheNotes;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button buttonAjouter = (Button) findViewById(R.id.ajouterNote);
TableLayout tableLayoutNotes = (TableLayout) findViewById(R.id.tableNote);
editTexteRechercheNotes = (EditText) findViewById(R.id.rechercheNote);
if(savedInstanceState != null){
monBlocNotes = (BlocNotes)savedInstanceState.getParcelable(STATE_BLOC_NOTES);
editTexteRechercheNotes.setText(savedInstanceState.getString(STATE_RECHERCHE));
}else{
monBlocNotes = new BlocNotes();
}
if(getIntent().hasExtra("nouvelleNote")) {
Note nouvelleNote = getIntent().getParcelableExtra("nouvelleNote");
monBlocNotes.ajouterNote(nouvelleNote);
}
for(Note n: monBlocNotes.getMesNotes()){
TableRow row = new TableRow(this);
TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT);
row.setLayoutParams(lp);
TextView textTitreNote = new TextView(this);
textTitreNote.setText(n.getTitre() + " " + n.getDateModif());
row.addView(textTitreNote);
tableLayoutNotes.addView(row,lp);
}
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putParcelable(STATE_BLOC_NOTES, monBlocNotes);
savedInstanceState.putString(STATE_RECHERCHE, editTexteRechercheNotes.getText().toString());
super.onSaveInstanceState(savedInstanceState);
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
monBlocNotes = (BlocNotes)savedInstanceState.getParcelable(STATE_BLOC_NOTES);
editTexteRechercheNotes.setText(savedInstanceState.getString(STATE_RECHERCHE));
}
public void ajouterUneNote(View v){
Intent intent = new Intent(this,NoteActivity.class);
startActivity(intent);
}
}
我尝试了一些事情,但没有结果。
logcat的:
02-05 21:32:13.384 1679-2274/com.google.process.gapps E/Backup﹕ [LegacyBackupAccountManager] Fail to get legacy transport context.
android.content.pm.PackageManager$NameNotFoundException: Application package com.google.android.backup not found
at android.app.ContextImpl.createPackageContextAsUser(ContextImpl.java:2139)
at android.app.ContextImpl.createPackageContext(ContextImpl.java:2115)
at android.content.ContextWrapper.createPackageContext(ContextWrapper.java:658)
at com.google.android.gms.backup.am.<init>(SourceFile:47)
at com.google.android.gms.backup.a.a(SourceFile:65)
at com.google.android.gms.backup.c.a(SourceFile:39)
at com.google.android.gms.backup.b.a(SourceFile:67)
at com.google.android.gms.backup.b.a(SourceFile:39)
at com.google.android.gms.backup.BackupAccountNotifierService.onHandleIntent(SourceFile:76)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)