Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从BroadcastReceiver OnReceiver()更新ListView_Java_Android_Parsing_Android Intent - Fatal编程技术网

Java 从BroadcastReceiver OnReceiver()更新ListView

Java 从BroadcastReceiver OnReceiver()更新ListView,java,android,parsing,android-intent,Java,Android,Parsing,Android Intent,我想从我的自定义广播接收器更新listview。实现这种功能的最佳方式是什么?这是我的接收代码。 我正在构建一个使用解析API的消息传递应用程序。我尝试从广播机更新适配器,但它一直强制关闭 package com.example.datatest; import java.util.Iterator; import org.json.JSONException; import org.json.JSONObject; import android.app.NotificationManager

我想从我的自定义广播接收器更新listview。实现这种功能的最佳方式是什么?这是我的接收代码。 我正在构建一个使用解析API的消息传递应用程序。我尝试从广播机更新适配器,但它一直强制关闭

package com.example.datatest;

import java.util.Iterator;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
public class MyCustomReceiver extends BroadcastReceiver {
private static final String TAG = "MyCustomReceiver";
@Override

public void onReceive(Context context, Intent intent) {


try {
  String action = intent.getAction();
  String channel = intent.getExtras().getString("com.parse.Channel");
  JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
  PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent,
          PendingIntent.FLAG_UPDATE_CURRENT);

  // Create Notification using NotificationCompat.Builder
  NotificationCompat.Builder builder = new NotificationCompat.Builder(
          context)
          // Set Icon
          .setSmallIcon(R.drawable.icon)
          // Set Ticker Message
          .setTicker("New Message")
          // Set Title
          .setContentTitle("MESSAGE")
          // Set Text
          .setContentText("TEST")
          // Add an Action Button below Notification
          .addAction(R.drawable.ic_launcher, "Action Button", pIntent)
          // Set PendingIntent into Notification
          .setContentIntent(pIntent)
          // Dismiss Notification
          .setAutoCancel(true);

  // Create Notification Manager
  NotificationManager notificationmanager = (NotificationManager) context
          .getSystemService(Context.NOTIFICATION_SERVICE);
  // Build Notification with Notification Manager
  notificationmanager.notify(0, builder.build());
  Log.d(TAG, "got action " + action + " on channel " + channel + " with:");
  Iterator itr = json.keys();
  while (itr.hasNext()) {
    String key = (String) itr.next();
    Log.d(TAG, "..." + key + " => " + json.getString(key));
  }
} catch (JSONException e) {
  Log.d(TAG, "JSONException: " + e.getMessage());
}
 }
}

修复了我的问题,我在清单中的BroadcastReceiver中使用了不必要的操作。

您可以创建回调接口,在接收方中设置它,使ui类实现这些方法。就这样