0

Hello i dsplayed notification and according to the distance from circle i displayed notification and i want to send all marker emailid to pending intent activity.

Here is my code

@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();
    }
}

According to my code it will pass only first value i want all arraylist to pass to next activity

here is offeractivity

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());
}

}

unknown apk
  • 147
  • 1
  • 10
  • change this `if (distance[0] <= circle.getRadius()) ` to this `if (distance[i] <= circle.getRadius()) {` – Stephen Apr 25 '17 at 09:46
  • distance is float float[] distance = new float[2]; – unknown apk Apr 25 '17 at 09:59
  • tell me that arraylist name ? `i want all arraylist to pass to next activity` – Stephen Apr 25 '17 at 10:06
  • Locationlist contain all the marker location mar_list contain all the marker from circle radious and abc contain all the latlang – unknown apk Apr 25 '17 at 10:09
  • i want to pass mar_list to next activity – unknown apk Apr 25 '17 at 11:06
  • it seems you have to do like [this](http://stackoverflow.com/questions/17453297/passing-arraylist-of-string-arrays-from-one-activity-to-another-in-android). And also debug properly,whether you are getting all values in arraylist before moving to next activity. – Stephen Apr 25 '17 at 12:31
  • Ya i am getting all the values before sending to next activity but in next activbity get only first index value – unknown apk Apr 26 '17 at 05:37

2 Answers2

0

try this:

compile this gradle compile 'com.google.code.gson:gson:2.7'

String str = new Gson().toJson(mar_list);

intent.putExtra("list",str);

get list from intent

YourModelClass model = new Gson().fromJson(str,YourModelClass.class);
Bhupat Bheda
  • 1,968
  • 1
  • 8
  • 13
0

In your MainActivity.java :

change this :

 intent.putExtra("list",mar_list);

to

intent.putStringArrayListExtra("list", mar_list);

offeractivity.java

Change this :

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

to

mylist = getIntent().getExtras().getStringArrayList("list");  
Stephen
  • 9,899
  • 16
  • 90
  • 137