Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] java – why getIntExtra() is always default value

Posted on November 11, 2022 By

Solution 1 :

At intent.putExtra(EXTRA_NUMBER, number); line, you put a String not a int format, so getIntExtra return default, try intent.getStringExtra(key) or intent.getExtras().get(key) .

Problem :

at first my declaration is:

     public static final String EXTRA_TEXT="com.example.application.example.EXTRA_TEXT";
    public static final String EXTRA_NUMBER="com.example.application.example.EXTRA_NUMBER";

my MainActivity get number and text:

        public void openActivity2(){
            EditText editText1 = (EditText) findViewById(R.id.edittext1);
            String text = editText1.getText().toString();
            EditText editText2 = (EditText) findViewById(R.id.edittext2);
            String number = (editText2.getText().toString());

          
          Intent intent = new Intent(this, Activity2.class);
            intent.putExtra(EXTRA_TEXT, text);
            intent.putExtra(EXTRA_NUMBER, number);
            startActivity(intent);
        }
    }

my Activity2 should get the number and text:

 protected void onCreate(Bundle savedInstanceState) {
        .......
        Intent intent=getIntent();
        String text = intent.getStringExtra(MainActivity.EXTRA_TEXT);
        int num=intent.getIntExtra(MainActivity.EXTRA_NUMBER,0);

The text is well received,
but the number value is always 0.

READ  [FIXED] Android viewbinding deprecation warning persists in Android Studio 4 after making appropriate update
Powered by Inline Related Posts
Android Tags:android, android-activity, default, java

Post navigation

Previous Post: [FIXED] React-native android build fails due to missing files in the gradle cache?
Next Post: Can I use Google storage instead of iCloud?

Related Posts

[FIXED] java – MVVM with Room and LiveData – How to get List from LiveData Android
[FIXED] android – I want to access response coming from API in array format in flutter how many ways are there to access it and use it in UI? Android
[FIXED] android – Problem with an element in xml and kotlin Android
[FIXED] java – How to focus viewHolder of recycler view in android? Android
[FIXED] flutter – Flutterfire cli not showing windows as an option for platform to support Android
[FIXED] xamarin.forms – Xamarin forms showing white screen is showing before splash screen Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Quel est le fromage qui porte le nom d’une commune de Côte d’Or et qui est produit en Haute-marne ?
  • Welches ist das beste Senioren Smartphone?
  • What is ISO benefit?
  • What do red bottom shoes represent?
  • Are ultrasonic cleaners safe for electronics?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme