Passing variables from one activity to another

Passing variables from one activity to another

Content Index :

Passing variables from one activity to another
Tag : android , By : zdyne
Date : November 29 2020, 01:01 AM

I wish this helpful for you You can pass variable through Intent. For example like this:
In your MainActivity
public void startActivity() {
    Intent intent = new Intent(this, SecondActivity.class);
    intent.putExtra("example-extra", 5);
protected void onCreate(@Nullable Bundle savedInstanceState) {
    int example_extra = getIntent().getIntExtra("example_extra", 0);

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Passing variables between service & activity and vice-versa

Tag : android , By : ikey
Date : March 29 2020, 07:55 AM
around this issue as general there a three main ways to commnicate with Services
1-Binder (in bind service) 2-Messenger 3-AIDL
Using AIDL is necessary only if
 Using Binder 
 Using Messenger

Need helping passing variables from listview item to another activity

Tag : android , By : Pat
Date : March 29 2020, 07:55 AM
wish helps you Change your onListItemClick code as for getting selected value from Cursor:
    protected void onListItemClick(ListView l, View v, int position, long thisID)
      Cursor cursor = ((SimpleCursorAdapter)l.getAdapter()).getCursor();
      long id = cursor.getLong(cursor.getColumnIndex("YOUR_COLUMN_NAME_HERE"));

      Intent startDayActivity = new Intent(DaysActivity.this, DayActivity.class);
      startDayActivity.putExtra("routineDataID", id);

Android - Passing a variables to another activity

Tag : android , By : mgz
Date : March 29 2020, 07:55 AM
wish of those help I want to pass a Variable to my DBConnector.Java where I am executing an SQLite query but I am not sure how to do that and need some help. , Use Intent to pass your data :
Bundle extras = getIntent().getExtras();
String a = extras.getString("myRub");

Android Passing Variables to another activity with # not working as expected

Tag : android , By : new Blackberry devel
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I don't think your regex is being evaluated correctlyTry using the following regex
 String tag = getIntent().getData().getQueryParameter("tag");
 String tag = getIntent().getExtras().getString("tag");
 new Intent(...).putExtra("tag", hashTagString);

Passing variables from MainActivity to another Activity to a tab Fragment

Tag : java , By : artifex
Date : March 29 2020, 07:55 AM
will be helpful for those in need I have a variable in MainActivity that I have successfully passed to StoriesActivity. , Here is solution to your problem:
This is your activity:
public class StoriesActivity extends AppCompatActivity {

    //This is our tablayout
    private TabLayout tabLayout;

    //This is our viewPager
    private ViewPager viewPager;

    private Toolbar toolbar;

    private int authorID;
    private String authorName;

    protected void onCreate(Bundle savedInstanceState) {

        /* +++ START Intent +++ */
        Bundle extras = getIntent().getExtras();

        authorID = extras.getInt("author_id");
        authorName = extras.getString("author_name");
        Log.i("click", Integer.toString(authorID));
        // this is successful
        /* +++ END Intent +++ */

        toolbar = (Toolbar) findViewById(R.id.toolbar);

        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

        viewPager = (ViewPager) findViewById(R.id.viewpager);

        tabLayout = (TabLayout) findViewById(R.id.tabs);

    private void setupViewPager(ViewPager viewPager) {
        ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
        adapter.addFragment(StoriesFragment.newInstance(authorID, authorName), "Stories");
        adapter.addFragment(new CollectionsFragment(), "Collections");

    class ViewPagerAdapter extends FragmentPagerAdapter {
        private final List<Fragment> mFragmentList = new ArrayList<>();
        private final List<String> mFragmentTitleList = new ArrayList<>();

        public ViewPagerAdapter(FragmentManager manager) {

        public Fragment getItem(int position) {
            return mFragmentList.get(position);

        public int getCount() {
            return mFragmentList.size();

        public void addFragment(Fragment fragment, String title) {

        public CharSequence getPageTitle(int position) {
            return mFragmentTitleList.get(position);
public class StoriesFragment extends Fragment {

    private int authorID;
    private String authorName;

    public StoriesFragment() {
        // Required empty public constructor

    public static StoriesFragment newInstance(int authorID, String authorName) {

        Bundle args = new Bundle();
        args.putInt("author_id", authorID);
        args.putString("author_name", authorName);

        StoriesFragment fragment = new StoriesFragment();
        return fragment;

    private ListView storiesListView;

    public void onCreate(Bundle savedInstanceState) {

        // Here is your arguments
        authorID = getArguments().getInt("author_id");
        authorName = getArguments().getString("author_name");

        // link ListView object with XML ListView
        storiesListView = (ListView) findViewById(R.id.stories_list_view);

        // create new instance of DatabaseHelper
        DatabaseHelper db = new DatabaseHelper(this);

        // create list of stories through getAllStories method
        List<Book> storyList = db.getAllStories(authorID);

        // create new ArrayAdapter
        ArrayAdapter<Book> arrayAdapter =
                new ArrayAdapter<Book>(this, android.R.layout.simple_list_item_1, storyList);

        // link ListView and ArrayAdapter

        Log.i("test", storyList.toString());

        storiesListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                Book story = (Book) storiesListView.getItemAtPosition(i);
                //Log.i("click", story);

                Intent intent = new Intent(StoriesActivity.this, StoryBodyActivity.class);
                intent.putExtra("story", story.getTitle());

                //Log.i("click", "That's a click!");


    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_stories, container, false);

Related Posts Related QUESTIONS :
  • why I receive "bad request" in my request by retrofit
  • Intercept NavigationUI.onNavDestinationSelected() to make backstack pop with "inclusive = true"
  • I have a problem with the navigation fragments in my proyect, it sais that I need a defaut nav host atribute but I alrea
  • How can I keep a BottomSheetDialogFragment height to always match_parent?
  • How to reference a timerPicker in android studio using kotlin
  • Firebase Crashlytics - get stacktrace info to display during CrashlyticsListener.crashlyticsDidDetectCrashDuringPrevious
  • Schedule a repeating alarm clock
  • Can't assign values outside onTouchListener
  • Is setContentView() needed to inflate a fragment?
  • Why instead of string method returns Kotlin.Unit?
  • Retrofit slash as Query
  • When does onCreateView() get called in this app?
  • Fragment is reloaded each time after rejecting location permission
  • How to read ViewModel data from sttrings.xml list of items
  • Flutter doctor does not see vs code ,VS code does not detect flutter/bin
  • How to build aar in flutter
  • Is displayMetrix xdpi and ydpi accurate?
  • How to detect doubletap on a View?
  • how to play an encrypted file in Android
  • Android: keytool error on the command line when locating debug.keystore
  • Android paint/canvas issue; drawing smooth curves
  • Problems with starting an activity in onStart
  • Performance of map overlay in conjunction with ItemizedOverlay is very poor
  • How to change android indeterminate ProgressBar color?
  • How do I change the Mobile Country Code (MCC) in the Android Emulator?
  • Stop Progressbar manual scrolling in Android
  • Android: download large file
  • Android : uploaded .apk file to server but cant download that .apk file
  • How do I distribute Android app to beta tester without using Market
  • Android Unable to launch the Inbox from a notification
  • Android: Ringer mode changed to silent doesn't stop the phone vibrating
  • Change the side the text appears on a radio button
  • Check the memory usage anp cpu and power of an application in android
  • What is the String 'volumeName' argument of MediaStore.Audio.Playlists.Members.getContentUri referring to?
  • Playing Multiple sounds at the same time in Android
  • Android: how to change the time in emulator?
  • close the soft key pad when i click on other views in android
  • Setting the position within a spinner
  • How to play ringtone/alarm sound in Android
  • How to adjust text font size to fit textview
  • "Android 2.x" vs "Google APIs" for Android AVD Setup
  • How to center buttons on screen horizontally and vertically plus equidistant apart?
  • Discrete seekbar in Android app?
  • Gradle Build Fails - Illegal exception table range in class file com/google/wireless/android/sdk/stats/GradleBuildMemory
  • register has type Long (High Half) but expected Long (Low Half)
  • Is it good idea to use Dispatcher.Main with delay( )?
  • WebView and Advanced View is Not loading partiucalr URL
  • How to show three dots at the end of text view
  • Is it possible to run macros within Android Studio project?
  • Adding a button with default appearance but changed background color
  • What is best way to show notification at a certain time in Android?
  • Jetifier not working when library uses android component and app uses androidx component
  • How can I write the contents of an image in a filesystem
  • Retrieve a list of images from the Database and display them using a ListView?
  • java.lang.SecurityException: my location requires permission ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION
  • Timer/hourglass wont stop
  • How can I make AndroidX the default library for new Android projects?
  • Is it okay to delete buildToolsVersion android studio because of a warning in the Asyncstorage library?
  • Can I call a class that doesn't have an activity withIntent?
  • Android TextView fontFamily not working when set via TextAppearance
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com