android-bundle

Using intent and bundle for integers in Android

送分小仙女□ 提交于 2019-12-12 03:01:12
问题 Say I wanted to pass data from one activity/class to the other involving an integer data type. Here's what I have for the MainActivity (first) class so far: @Override public void onClick(View v) { Intent i = new Intent(this, SecondActivity.class); final int x = 3; i.putExtra("new variable", x); startActivity(i); } For the receiving class, SecondActivity: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); Bundle i

Sending Intent from BroadcastReceiver class to currently running activity

大兔子大兔子 提交于 2019-12-09 11:33:09
问题 I have a class which extends BroadcastReceiver . On receiving a SMS, I would like to pass information to my main activity class to display the text in a box (Append, if already text is present). public class SmsReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent i = new Intent(context, MainActivity.class); i.putExtra("updatedString","Hello"); context.startActivity(i); } } MainActivity.java public class MainActivity extends Activity{

Retrieve android.intent.extra.EMAIL value from bundle

纵然是瞬间 提交于 2019-12-07 18:05:27
问题 I created one app like email clients app such as Gmail . When user click on email address in another apps and choose my app from email sending apps in list appear on . The email content like email address , email subject and .... come to my app by intent . But the problem is intent.getData(); is null value all of the time and i try to get email data from intent . I tested bundle in intent and i saw its not null and when i write this code : bundle = intent.getExtras(); Log.e("Email",bundle

Android getIntent().getExtras() returning null sometimes

不打扰是莪最后的温柔 提交于 2019-12-07 05:01:01
问题 I was going through Crashlytics logs for my app and found that there is a NullPointerException on some devices because getIntent().getExtras() is returning null. This behavior is seen only on a few devices and I am not able to reproduce this bug. I know that I can check in the activity if the Bundle is null and prevent the NullPointerException but I was more interested in finding out the root cause for this behavior. Edit: Source - listView.setOnItemClickListener(new AdapterView

Send argument through PendingIntent of NavDeepLinkBuilder

空扰寡人 提交于 2019-12-05 19:00:18
I'm having some difficulties sending an argument through a PendingIntent of a notification using NavDeepLinkBuilder . I'm able to get the destination Activity to launch by clicking the notification, but the Activity 's Intent doesn't contain the argument value that I passed it through the NavDeepLinkBuilder . The Intent instead returns the defaultValue that I set in the nav graph - "noJobId". Notification creation : val notification = NotificationCompat.Builder(context, context.getString(R.string.notification_channel_id_new_job)) ... .setContentIntent( NavDeepLinkBuilder(context)

Cannot launch AVD in emulator. ?android studio

南楼画角 提交于 2019-12-05 16:22:10
my emulator is not runnnig and gives the error in image below error image and test at run window C:\Users\Wahlah\AppData\Local\Android\sdk\tools\emulator.exe -netdelay gprs -netspeed full -avd Nexus_4_API_21 This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. terminate called after throwing an instance of 'std::logic_error' what(): basic_string::_S_construct null not valid and second error exist is this image ERROR 2 et_l I got the same problem with the same logged warnings and errors (and the alert

Android getIntent().getExtras() returning null sometimes

匆匆过客 提交于 2019-12-05 11:42:44
I was going through Crashlytics logs for my app and found that there is a NullPointerException on some devices because getIntent().getExtras() is returning null. This behavior is seen only on a few devices and I am not able to reproduce this bug. I know that I can check in the activity if the Bundle is null and prevent the NullPointerException but I was more interested in finding out the root cause for this behavior. Edit: Source - listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

Store and retrieve array list in Bundle in Android

ε祈祈猫儿з 提交于 2019-12-05 01:30:16
How do I store and retrieve an array list of values in a Bundle in Android? Any examples? Lets take if you array list has strings in it. ArrayList<String> al = new ArrayList<String>(); al.add("test1"); al.add("test2"); al.add("test3"); Now you can put it into bundle as follows: Bundle value= new Bundle(); value.putStringArrayList("temp1", al); If you have your own object type instead of "String" in ArrayList then you need to serialize that ArrayList object. eMich Serialize your arraylist using the Parcelable class. You can add Parcelables to the Bundle. The only way to store an arraylist in

Android Studio: Passing multiple values using intent PROVIDES ONLY 1 VALUE?

半腔热情 提交于 2019-12-04 19:53:51
I am trying to make a quiz where users choose an answer in each activity, and the final page provides an answer based on the chosen options. Therefore, I want to pass these values to the final activity, but only the last chosen value seems to show. First Activity: public class Quiz extends Activity { Button btn; RadioGroup rg; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.quiz); btn = (Button) findViewById(R.id.nextBtn); rg= (RadioGroup) findViewById(R.id.rg); btn.setOnClickListener(new View.OnClickListener() {

Does retrieving a parcelable object through bundle always create new copy?

喜欢而已 提交于 2019-12-04 17:22:07
问题 I'm passing a parcelable object to a fragment by adding into a bundle while creating the fragment. In onc instance modification to this parcelled object reflects modification in original object and in another case it is not. I'm a little baffled by this behaviour. Till now I have assumed retrieving a parcelled objects through a bundle always create new object[no sure whether it's shallow copy or deep copy]. Someone please clarify parcelable behaviour. 回答1: I was struggling with a similar