从arraylist发送通知单击时,仅从arraylist中获取一个元素



您好,我dsplay通知,根据我显示的通知的距离,我想将所有标记emailID发送到待定的意图活动。

这是我的代码

@Override
public void onLocationChanged(Location location) {
    if (circle != null)
        circle.remove();
    this.location = location;
    double latitude = location.getLatitude();
    double longitude = location.getLongitude();
    LatLng latLng = new LatLng(latitude, longitude);
//        googleMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
    googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(14));
    circle = googleMap.addCircle(new CircleOptions()
            .center(new LatLng(latitude, longitude))
            .strokeColor(Color.RED)
            .strokeWidth(2)
            .radius(1000));
    circle.setCenter(latLng);

    float[] distance = new float[2];
    if (!abc.isEmpty()) {
        mar_list=new ArrayList<>();
        for (int i = 0; i < abc.size(); i++) {
            Location.distanceBetween(abc.get(i).latitude, abc.get(i).longitude, circle.getCenter().latitude, circle.getCenter().longitude, distance);
            if (distance[0] <= circle.getRadius()) {
                mar_list.add(locationlist.get(i).get("usrnm"));
                manager1 = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                Intent intent = new Intent(MainActivity.this, OfferActivity.class);
                intent.putExtra("list",mar_list);
                Log.v("TAG",""+mar_list.toString());
                //Here mar_list contain three items but in offer activity only one item is displayed      
                PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
                mBuilder = new NotificationCompat.Builder(this);
                mBuilder.setOngoing(false);
                Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
                mBuilder.setContentTitle("Offer")
                        .setStyle(new NotificationCompat.BigTextStyle().bigText("You Have Entered in Offer zone.To see offer in your area please proceed"))
                        .setContentText("You Have Entered in Offer zone.To see offer in your area please proceed")
                        .setLargeIcon(largeIcon)
                        .setContentIntent(pendingIntent)
                        .setVibrate(new long[]{1000, 1000, 1000, 1000, 1000})
                        .setAutoCancel(true)
                        .setSmallIcon(R.mipmap.ic_launcher);
                manager1.notify(1, mBuilder.build());

            } else {
                Log.v("TAG ", "" + distance[0] + " radius: " + circle.getRadius());
                Toast.makeText(getBaseContext(), "outside, distance from center: " + distance[0] + " radius: " + circle.getRadius(), Toast.LENGTH_LONG).show();
            }
        }
        Log.v("TAG",""+mar_list.toString());
    } else {
        Log.v("TAG ", "" + distance[0] + " radius: " + circle.getRadius());
        Toast.makeText(getBaseContext(), "outside, distance from center: " + distance[0] + " radius: " + circle.getRadius(), Toast.LENGTH_LONG).show();
    }
}

根据我的代码,它将仅通过第一个值,我希望所有arraylist都传递到下一个活动

这是要约

public class OfferActivity extends AppCompatActivity {
ArrayList<String> mylist;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_offer);
    mylist = (ArrayList<String>) getIntent().getSerializableExtra("list");
    Log.v("TAG", "" + mylist.toString());
}

}

尝试以下:

编译此Gradle compile 'com.google.code.gson:gson:2.7'

String str = new Gson().toJson(mar_list);
intent.putExtra("list",str);

从意图获取列表

YourModelClass model = new Gson().fromJson(str,YourModelClass.class);

在您的 mainActivity.java 中:

更改此内容:

 intent.putExtra("list",mar_list);

to

intent.putStringArrayListExtra("list", mar_list);

upersactivity.java

更改此内容:

mylist = (ArrayList<String>) getIntent().getSerializableExtra("list");

to

mylist = getIntent().getExtras().getStringArrayList("list");  

相关内容

  • 没有找到相关文章

最新更新