1. Download our Official Android App: Forums for Android!

Apps Problem here in passing string to another activity

Discussion in 'Android Development' started by Mussa Kareem, May 18, 2016.

  1. Mussa Kareem

    Mussa Kareem Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Oct 17, 2015

    Oct 17, 2015
    1
    0
    5
    Male
    package biketracker1.com.biketracker;

    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.telephony.SmsMessage;
    import android.util.Log;
    public class SmsReceiver extends BroadcastReceiver

    {
    Context context;
    private String latitudes;
    @override
    public void onReceive(Context context, Intent intent)
    {

    Log.e("ABC", "** good");

    if(intent.getAction().equalsIgnoreCase("android.provider.Telephony.SMS_RECEIVED"))
    {
    Bundle bundle = intent.getExtras();
    if (bundle != null)
    {
    Object[] pdus = (Object[]) bundle.get("pdus");
    final SmsMessage[] messages = new SmsMessage[pdus.length];
    for (int i = 0; i < pdus.length; i++)
    {
    messages = SmsMessage.createFromPdu((byte[]) pdus);


    }

    if (messages.length > -10)
    {Log.e("ABC",messages[0].getMessageBody().toString());
    // Toast.makeText(context, "SMS Message content" +messages, Toast.LENGTH_LONG).show();
    Intent j = new Intent(context,MapsActivity.class);
    j.putExtra("messages",latitudes);
    context.startActivity(j);

    // NetComm.SendMessage("me", messages[0].getOriginatingAddress(), messages[0].getMessageBody());
    }
    }
    }
    }}



    Other Activity

    package biketracker1.com.biketracker;

    import android.content.Intent;
    import android.os.Bundle;
    import android.support.v4.app.FragmentActivity;

    import com.google.android.gms.maps.CameraUpdateFactory;
    import com.google.android.gms.maps.GoogleMap;
    import com.google.android.gms.maps.OnMapReadyCallback;
    import com.google.android.gms.maps.SupportMapFragment;
    import com.google.android.gms.maps.model.LatLng;
    import com.google.android.gms.maps.model.MarkerOptions;

    public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;
    private String getLangs;
    private String [] getValues;

    @override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    Intent intent = getIntent();

    getLangs = intent.getExtras().getString("messages");
    getValues = getLangs.split(",");

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
    .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
    }


    @override
    public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    LatLng sydney = new LatLng(Double.parseDouble(getValues[0]),Double.parseDouble(getValues[1]));

    mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Lahore"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
    }
     

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,889
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,889
    11,551
    1,988
    Male
    Software developer
    South West of England
    And the problem is....?

    At a wild guess, I'm thinking that your receiver Activity gets an empty, or null string from the Intent bundle, which causes a null pointer error when you call method split() on a null object?
    That's probably because you declare variable lattitudes, but never assign it a value.

    I think you probably meant to use variable messages as the data for your Intent bundle.

    Please place your code in [code][/code] tags, as described here

    http://androidforums.com/threads/please-read-me-before-posting.987318/
     
    #2 LV426, May 19, 2016
    Last edited: May 19, 2016
    scary alien likes this.

Share This Page

Loading...