0

I did search a lot but I couldn't found my answer. If any one can help, much appreciated.

I am building an android application from that can I launch another application along with passing some required data?

Example. MyApplication launch "AnotherApplication" that needs username and password. So can I launch that "AnotherApplication" along with passing these two parameters?

I don't have control on "AnotherApplication" code. So I can not read data from Intent or something in this. And I dont even know how that application is reading these two parameters(Intent/ input's value etc.)

Is it technically possible? If yes please provide me sample snippet as well to achieve this.

Giriraj
  • 1
  • 3
  • possible duplicate of [Data passing to another application in Android](http://stackoverflow.com/questions/24513473/data-passing-to-another-application-in-android) – Narendra Singh Jun 17 '15 at 11:17
  • you can use - intent.putExtra("Key", "Your data here"); in a similar way as for data passing between the Activities. – Narendra Singh Jun 17 '15 at 11:19
  • Thanks for quick answers but I do not have control on target application which I am going to launch. So I cannot read data from Intent.getExtra..() kind of things. – Giriraj Jun 17 '15 at 11:50
  • If you don't have control on target application, why do you want to pass the data? – Narendra Singh Jun 17 '15 at 11:55
  • Can you elaborate, what you actually want? – Narendra Singh Jun 17 '15 at 11:55
  • In order to pass the data between applications.....one should be sender....and the other one should be receiver......so, you must have control on both and be able to putExtra and getExtra too. – Narendra Singh Jun 17 '15 at 11:58
  • Yes one should be reciever but the code of receiver is not mine. But I wanted to enter into that (Third party) application without providing the parameters which are been already provided in my application. Basically I wanted to replay those parameters. But I am not sure whether its possible technically or not. – Giriraj Jun 17 '15 at 12:48

2 Answers2

0

Yes, you can attach data, either primitive or Serializable or Parceable, into Intent. Please see enter link description here

Community
  • 1
  • 1
Qylin
  • 1,501
  • 1
  • 16
  • 26
0

yes this is a complete example

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity implements OnClickListener {
  
  EditText etFName;
  EditText etLName;
  
  Button btnSubmit;
  
  
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        etFName = (EditText) findViewById(R.id.etFName);
        etLName = (EditText) findViewById(R.id.etLName);
        
        btnSubmit = (Button) findViewById(R.id.btnSubmit);
        btnSubmit.setOnClickListener(this);
        
    }


  @Override
  public void onClick(View v) {
    Intent intent = new Intent(this, ViewActivity.class); 
    intent.putExtra("fname", etFName.getText().toString());
    intent.putExtra("lname", etLName.getText().toString());
    startActivity(intent);
  } 
}

and here the other activity

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class ViewActivity extends Activity {
  
  TextView tvView;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.view);
    
    tvView = (TextView) findViewById(R.id.tvView);
    
    Intent intent = getIntent();
    
    String fName = intent.getStringExtra("fname");
    String lName = intent.getStringExtra("lname");
    
    tvView.setText("Your name is: " + fName + " " + lName);
  }
} 
Andrea Cinesi
  • 276
  • 2
  • 10