我正在使用谷歌提供的Mobile Backend启动器。我已经添加了自己的活动,我正在使用 CloudBackend 和 CloudBackendFragment 类。当我尝试打开活动时,它会崩溃。我认为这是因为我在onCreate方法中初始化的CloudBackendFragment对象。但是根据示例留言簿活动,我需要它来执行插入和查询数据存储区。 代码
public class Regform extends Activity implements OnListener{
private CloudBackendFragment mProcessingFragment1;
private FragmentManager mFragmentManager;
private Button register;
private Button show;
private static final String PROCESSING_FRAGMENT_TAG = "BACKEND_FRAGMENT";
private static final String TAG="Registration";
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(TAG,"Entered the onCreate method");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_regform);
final EditText firstName = (EditText) findViewById(R.id.firstName);
final EditText lastName = (EditText) findViewById(R.id.lastName);
final EditText email = (EditText) findViewById(R.id.email);
final EditText phoneNumber = (EditText) findViewById(R.id.phone);
final EditText username = (EditText) findViewById(R.id.userName);
final EditText password = (EditText) findViewById(R.id.password);
register = (Button) findViewById(R.id.register);
show=(Button) findViewById(R.id.Show);
final Button login = (Button) findViewById(R.id.login);
mFragmentManager=getFragmentManager();
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
mProcessingFragment1 = (CloudBackendFragment) mFragmentManager.
findFragmentByTag(PROCESSING_FRAGMENT_TAG);
// If not retained (or first time running), create a new one
if (mProcessingFragment1 == null) {
mProcessingFragment1 = new CloudBackendFragment();
mProcessingFragment1.setRetainInstance(true);
fragmentTransaction.add(mProcessingFragment1, PROCESSING_FRAGMENT_TAG);
}
fragmentTransaction.commit();
register.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Log.i(TAG,"Entered the regiter method");
CloudEntity reg = new CloudEntity("Registration");
reg.put("FirstName", firstName.getText().toString());
reg.put("LastName", lastName.getText().toString());
reg.put("Email", email.getText().toString());
reg.put("phoneno", phoneNumber.getText());
reg.put("username",username.getText().toString());
reg.put("password",password.getText().toString());
CloudCallbackHandler<CloudEntity> handler = new CloudCallbackHandler<CloudEntity>() {
@Override
public void onComplete(final CloudEntity result) {
firstName.setText("");
lastName.setText("");
email.setText("");
phoneNumber.setText("");
firstName.setEnabled(true);
lastName.setEnabled(true);
email.setEnabled(true);
phoneNumber.setEnabled(true);
register.setEnabled(true);
password.setEnabled(true);
username.setEnabled(true);
}
@Override
public void onError(final IOException exception) {
handleEndpointException(exception);
}
};
// execute the insertion with the handler
mProcessingFragment1.getCloudBackend().insert(reg, handler);
firstName.setEnabled(false);
lastName.setEnabled(false);
email.setEnabled(false);
phoneNumber.setEnabled(false);
register.setEnabled(false);
}
});
我对app引擎和android都比较新。请帮帮我。