Sending intent with bundle using console
According to the source code am
has no way of accepting input data of the bundle
type
Update:
In Android 7.0 the intent parameters parsing code has been moved from Am.java to Intent.java and support for more data types (like Array[]
and ArrayList<>
of basic types) has been added. Unfortunately there is still no support for the Bundle
type extras in am
command.
How to include a bundle extra when testing Android broadcasts?
In this post say it is impossible to put bundle extra through adb. You can write simple test application and send app invite intent what you want:
Intent intent = new Intent("com.android.vending.INSTALL_REFERRER");
intent.setPackage("your_package");
Bundle bundle = new Bundle();
bundle.putString("com.android.vending.INSTALL_REFERRER", "your_invite_id");
bundle.putString("com.google.android.gms.appinvite.DEEP_LINK", "your_deep_link");
intent.putExtra("com.google.android.gms.appinvite.REFERRAL_BUNDLE", bundle);
sendBroadcast(intent);
I have tested google app invite in this way, but before tried to sent intent through adb too.
How to send byte[] intent extra value from command line?
It seems that there is no option for byte array extra.
Details:
https://developer.android.com/studio/command-line/adb#IntentSpec
Do you really need to send intent by byte array? How about send it by "integer array extra", and cast it to byte?
Passing value from one activity to another using intent
Change
i.putExtra(mobileno1, mobileno1);
to
i.putExtra("mobileno1", mobileno1);
You must pass key value pair. You are passing mobileno1
's value in key, too. So you can't retrieve it using key = "mobileno1"
To avoid null pointer use this:
if (getIntent().getStringExtra("mobileno1") != null) {
edtnum.setText(getIntent().getStringExtra("mobileno1"));
}
Hope its clear :)
Edit:
If you want to execute some code like that, make sure you add the TextChangedListener
before you call setText
.
Example:
This code didn't work for me:
setContentView(R.layout.activity_main);
e = (EditText) findViewById(R.id.etext);
e.setText(myString);
e.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
System.out.println("on");
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
System.out.println("after");
}
});
But if I call setText
later to adding textChangedListener
, it work fine, and I am able to see sysouts in console.
setContentView(R.layout.activity_main);
e = (EditText) findViewById(R.id.etext);
e.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
System.out.println("on");
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
System.out.println("after");
}
});
e.setText(myString);
Hope it helps.
Is it possible to send HashMap as extra in adb shell am broadcast?
Unfortunately it is not possible using am
(at the moment).
All command line options that can be parsed by am
can be seen in its sources: https://github.com/android/platform_frameworks_base/blob/master/cmds/am/src/com/android/commands/am/Am.java.
You can try to build your own am
with such functionality (if it's necessary enough).
send Arraylist by Intent
The first part to understand is that you pass information from Activity A to Activity B using an Intent
object, inside which you can put "extras". The complete listing of what you can put inside an Intent
is available here: https://developer.android.com/reference/android/content/Intent.html (see the various putExtra()
methods, as well as the putFooExtra()
methods below).
Since you are trying to pass an ArrayList<Song>
, you have two options.
The first, and the best, is to use putParcelableArrayListExtra()
. To use this, the Song
class must implement the Parcelable
interface. If you control the source code of Song
, implementing Parcelable
is relatively easy. Your code might look like this:
Intent intent = new Intent(ActivityA.this, ActivityB.class);
intent.putParcelableArrayListExtra("songs", songs);
The second is to use the version of putExtra()
that accepts a Serializable
object. You should only use this option when you do not control the source code of Song
, and therefore cannot implement Parcelable
. Your code might look like this:
Intent intent = new Intent(ActivityA.this, ActivityB.class);
intent.putSerializableExtra("songs", songs);
So that's how you put the data into the Intent
in Activity A. How do you get the data out of the Intent
in Activity B?
It depends on which option you selected above. If you chose the first, you will write something that looks like this:
List<Song> mySongs = getIntent().getParcelableArrayListExtra("songs");
If you chose the second, you will write something that looks like this:
List<Song> mySongs = (List<Song>) getIntent().getSerializableExtra("songs");
The advantage of the first technique is that it is faster (in terms of your app's performance for the user) and it takes up less space (in terms of the size of the data you're passing around).
Related Topics
Android - Nestedscrollview Which Contains Expandablelistview Doesn't Scroll When Expanded
Broadcast Receiver Not Working in Android Oreo
Speed Up 'Navigation Drawer' Animation Speed on Closing
Bitmap Too Large to Be Uploaded into a Texture
Picasso Loading of Image Spawned Inside Asynctask
Android Facebook Authorization - Can Not Log in When Official Facebook App Is Installed
Android: How Handle Message Error from the Server Using Volley
How to Parse the CSV File in Android Application
Android M Fingerprintmanager.Ishardwaredetected() Returns False on a Samsung Galaxy S5
Android Change Text Color of Items in Spinner
Compatiblity of Material Design to Versions Below Android 5.0
Getactionview() of My Menuitem Return Null
Checkbox Gets Unchecked on Scroll in a Custom Listview
Achartengine - Can't Figure How to Use Dates as X Axis - the File I Save Is Empty
Differencebetween Sendstickybroadcast and Sendbroadcast in Android