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

}

7
  • change this if (distance[0] <= circle.getRadius()) to this if (distance[i] <= circle.getRadius()) { Commented Apr 25, 2017 at 9:46
  • distance is float float[] distance = new float[2]; Commented Apr 25, 2017 at 9:59
  • tell me that arraylist name ? i want all arraylist to pass to next activity Commented Apr 25, 2017 at 10:06
  • Locationlist contain all the marker location mar_list contain all the marker from circle radious and abc contain all the latlang Commented Apr 25, 2017 at 10:09
  • i want to pass mar_list to next activity Commented Apr 25, 2017 at 11:06

2 Answers 2

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);
Sign up to request clarification or add additional context in comments.

Comments

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");  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.