Skip to content

Snappy1

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

[FIXED] Android Studio: multi-activity problem, activity does not move to next activity

Posted on November 11, 2022 By

Solution 1 :

Try this,

Intent i = new Intent(mamm.this, sua.class);
startActivityForResult(i, 0);

Problem :

I have some issues with Android Studio program
I am currently coding a multi-activity program.
Most activities work just fine, but some of my activities do not proceed to the next one.
Here are my codes.

public class mamm extends AppCompatActivity{

    ListView listview;
    String aGangList[] = {"a", "b"};
    String desAGangList[] = {"A", "B"};
    int imageList[] = {R.drawable.ddda, R.drawable.ddda};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mamm);

        listview = findViewById(R.id.agang);
        MyAdapter adapter = new MyAdapter(this, aGangList, desAGangList, imageList);
        listview.setAdapter(adapter);

        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (position == 0){
                    Toast.makeText(mamm.this, "a", Toast.LENGTH_SHORT).show();
                    Intent i = new Intent(view.getContext(), sua.class);
                    startActivityForResult(i, 0);
                }
                if (position == 1){
                    Toast.makeText(mamm.this, "b", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
   class MyAdapter extends ArrayAdapter<String>{

        Context context;
        String rTitle[];
        String rDes[];
        int rImage[];

        MyAdapter(Context c, String title[], String des [], int image[]){
            super(c, R.layout.row, R.id.title, title);
            this.context = c;
            this.rTitle = title;
            this.rDes = des;
            this.rImage = image;
        }

        @NonNull
        @Override
        public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
            LayoutInflater l = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View r = l.inflate(R.layout.row, parent, false);
            ImageView images = r.findViewById(R.id.image);
            TextView mTitle = r.findViewById(R.id.textView1);
            TextView mSub = r.findViewById(R.id.textView2);

            images.setImageResource(rImage[position]);
            mTitle.setText(rTitle[position]);
            mSub.setText(rDes[position]);

            return r;

        }
    }
}

this is my mamm class, and I want mamm activity to go to sua class when the listview is clicked.

public class sua extends AppCompatActivity{

    ListView listview;
    String haGangList[] = {"c", "d"};
    String desHaGangList[] = {"C", "d"};
    int imageList[] = {R.drawable.ddda, R.drawable.ddda};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sua);

        listview = findViewById(R.id.agang);
        MyAdapter adapter = new MyAdapter(this, haGangList, desHaGangList, imageList);
        listview.setAdapter(adapter);

        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (position == 0){
                    Toast.makeText(sua.this, "c", Toast.LENGTH_SHORT).show();
                }
                if (position == 1){
                    Toast.makeText(sua.this, "d", Toast.LENGTH_SHORT).show();
                    Intent i = new Intent(view.getContext(), taeban.class);
                    startActivityForResult(i, 1);
                }
            }
        });
    }

    class MyAdapter extends ArrayAdapter<String>{

        Context context;
        String rTitle[];
        String rDes[];
        int rImage[];

        MyAdapter(Context c, String title[], String des [], int image[]){
            super(c, R.layout.row, R.id.title, title);
            this.context = c;
            this.rTitle = title;
            this.rDes = des;
            this.rImage = image;
        }

        @NonNull
        @Override
        public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
            LayoutInflater l = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View r = l.inflate(R.layout.row, parent, false);
            ImageView images = r.findViewById(R.id.image);
            TextView mTitle = r.findViewById(R.id.textView1);
            TextView mSub = r.findViewById(R.id.textView2);

            images.setImageResource(rImage[position]);
            mTitle.setText(rTitle[position]);
            mSub.setText(rDes[position]);

            return r;

        }
    }
}

For some reason, mamm class does not move to sua class.

READ  [FIXED] android - Write a PCM encoded sounds with silence gaps using MediaCodec and MediaMuxer
Powered by Inline Related Posts

But when I substitute other classes instead of sua class, it works perfectly.

I don’t why it does not work.
Can you guys please help…

Comments

Comment posted by SHS

You may try debugging it as putting debug points to (1) mamm – startActivityforResult() (2) sua – first line to oncreate(). You should be able to find error in debug log.

Android Tags:android, android-activity

Post navigation

Previous Post: [FIXED] activity_main.xml for android studio stuck on loading
Next Post: Can a beginner learn Moonlight Sonata 1st Movement?

Related Posts

[FIXED] permissions – Android Q . FileChooser SecurityException Android
[FIXED] android studio – I want to use portrait option in manifest Android
[FIXED] android – Add and remove columns childs inside Gridview Android
[FIXED] How to handle SeekBar change on Android TV? Android
[FIXED] kotlin – Stopping an Android service (when back to the foreground) not working Android
[FIXED] java – Use a parameter to select data from SQlite database 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

  • Can VPN be traced by police?
  • Where were Kaiser-Frazer cars built?
  • How do you make gold rose gold paint?
  • What are the newest type of dentures?
  • Can you wear joggers as dress pants?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme