PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, July 12, 2022

[FIXED] How Send message from fragment to activity and received and use in activity?

 July 12, 2022     android, android-activity, android-fragments, message     No comments   

Issue

Please please don't minus my question i confused when googling. I used Android Tab Layout with Swipeable Views in my code for when user pressed setting button on an activity.

now I need send message from TopRatedFragment.java that extends from fragment to the activity that call the mainActivity of "Android Tab Layout with Swipeable Views".


Solution

Here's the solution:

Step 1 : From your fragment.

Intent i = new Intent(getActivity(), YourActivity.class);
        i.putExtra("key", "Your value1");
        i.putExtra("key2", "Your value2");
        i.putExtra("key3", "Your value3");
        getActivity().startActivity(i);

Step 2 : In your Activity where you want the result

Intent getResults = getIntent();
        String firstValue = getResults.getStringExtra("key1");
        String secondValue = getResults.getStringExtra("key2");
        String thirdValue = getResults.getStringExtra("key3");

Use those values your needs are.

Hope this helps.. :)



Answered By - mike20132013
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing