抱歉,如果这是一个简单的问题,但我对此很新,还在学习.
我有一个应用程序,当我的用户在输入他们的详细信息后单击按钮登录时,它崩溃与android.os.NetworkOnMainThreadException我发现这是因为我在主线程上执行网络操作并解决我需要使用AsyncTask,我被语法困住了.
单击按钮后,这是我的代码,调用函数进行连接,然后将json解析为sqlite db.
// Login button Click Event
btnLogin.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String email = inputEmail.getText().toString();
String password = inputPassword.getText().toString();
UserFunctions userFunction = new UserFunctions();
JSONObject json = userFunction.loginUser(email, password);
// check for login response
try {
if (json.getString(KEY_SUCCESS) != null) {
loginErrorMsg.setText("");
String res = json.getString(KEY_SUCCESS);
if(Integer.parseInt(res) == 1){
// user successfully logged in
// Store user details in SQLite Database
DatabaseHandler db = new DatabaseHandler(getApplicationContext());
JSONObject json_user = json.getJSONObject("user");
// Clear all previous …Run Code Online (Sandbox Code Playgroud) 使用支持GCM的应用程序,我可以接收消息.但是格式显示为Message:Bundle [{message = test,android.support.content.wakelock = 3,collapse_key = do_not_collapes,from = 3423423}]
如何指定仅显示消息数据密钥对?
GCM收到了消息意图
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
// The getMessageType() intent parameter must be the intent you received
// in your BroadcastReceiver.
String messageType = gcm.getMessageType(intent);
if (!extras.isEmpty()) { // has effect of unparcelling Bundle
/*
* Filter messages based on message type. Since it is likely that GCM will be
* extended in the future with new message types, just ignore …Run Code Online (Sandbox Code Playgroud)