How to create an Intent method2019 Community Moderator ElectionHow do save an Android Activity state using save instance state?Why is the Android emulator so slow? How can we speed up the Android emulator?How do I pass data between Activities in Android application?How to send an object from one Android Activity to another using Intents?How can I open a URL in Android's web browser from my application?Passing enum or object through an intent (the best solution)Sending an Intent to browser to open specific URLHow do I get extra data from intent on Android?How do I fix android.os.NetworkOnMainThreadException?Send Email Intent

A diagram about partial derivatives of f(x,y)

Violin - Can double stops be played when the strings are not next to each other?

How do I change two letters closest to a string and one letter immediately after a string using Notepad++?

What is the adequate fee for a reveal operation?

What did “the good wine” (τὸν καλὸν οἶνον) mean in John 2:10?

How to write cleanly even if my character uses expletive language?

"of which" is correct here?

Print a physical multiplication table

Describing a chess game in a novel

Why does a Star of David appear at a rally with Francisco Franco?

I am confused as to how the inverse of a certain function is found.

Why do newer 737s use two different styles of split winglets?

How to make healing in an exploration game interesting

Is there a place to find the pricing for things not mentioned in the PHB? (non-magical)

Is "upgrade" the right word to use in this context?

How do I hide Chekhov's Gun?

Why do passenger jet manufacturers design their planes with stall prevention systems?

Bach's Toccata and Fugue in D minor breaks the "no parallel octaves" rule?

Can I use USB data pins as power source

Knife as defense against stray dogs

Counting models satisfying a boolean formula

Shortcut for setting origin to vertex

How could a scammer know the apps on my phone / iTunes account?

Bacteria contamination inside a thermos bottle



How to create an Intent method



2019 Community Moderator ElectionHow do save an Android Activity state using save instance state?Why is the Android emulator so slow? How can we speed up the Android emulator?How do I pass data between Activities in Android application?How to send an object from one Android Activity to another using Intents?How can I open a URL in Android's web browser from my application?Passing enum or object through an intent (the best solution)Sending an Intent to browser to open specific URLHow do I get extra data from intent on Android?How do I fix android.os.NetworkOnMainThreadException?Send Email Intent










0















Is there any way to create a basic method, that enables me to create an intent with a few parameters.



public void setIntent(Class to, String key, String string) 
Intent intent = new Intent(this, to);
intent.putExtra(key, string);
startActivity(intent);



That was my primary idea but it isn't working. I'm not able to pass a class and I don't know if and how I could maybe pass an ajustable amount of extras with different variables.



Thanks!










share|improve this question






















  • Are you trying to go to another class or to make an action to the class you are ?

    – Spritzig
    Mar 6 at 20:51















0















Is there any way to create a basic method, that enables me to create an intent with a few parameters.



public void setIntent(Class to, String key, String string) 
Intent intent = new Intent(this, to);
intent.putExtra(key, string);
startActivity(intent);



That was my primary idea but it isn't working. I'm not able to pass a class and I don't know if and how I could maybe pass an ajustable amount of extras with different variables.



Thanks!










share|improve this question






















  • Are you trying to go to another class or to make an action to the class you are ?

    – Spritzig
    Mar 6 at 20:51













0












0








0








Is there any way to create a basic method, that enables me to create an intent with a few parameters.



public void setIntent(Class to, String key, String string) 
Intent intent = new Intent(this, to);
intent.putExtra(key, string);
startActivity(intent);



That was my primary idea but it isn't working. I'm not able to pass a class and I don't know if and how I could maybe pass an ajustable amount of extras with different variables.



Thanks!










share|improve this question














Is there any way to create a basic method, that enables me to create an intent with a few parameters.



public void setIntent(Class to, String key, String string) 
Intent intent = new Intent(this, to);
intent.putExtra(key, string);
startActivity(intent);



That was my primary idea but it isn't working. I'm not able to pass a class and I don't know if and how I could maybe pass an ajustable amount of extras with different variables.



Thanks!







android android-intent






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 6 at 20:45









Lasse Lasse

31




31












  • Are you trying to go to another class or to make an action to the class you are ?

    – Spritzig
    Mar 6 at 20:51

















  • Are you trying to go to another class or to make an action to the class you are ?

    – Spritzig
    Mar 6 at 20:51
















Are you trying to go to another class or to make an action to the class you are ?

– Spritzig
Mar 6 at 20:51





Are you trying to go to another class or to make an action to the class you are ?

– Spritzig
Mar 6 at 20:51












3 Answers
3






active

oldest

votes


















0














 // Generalized method
private void startActivityGeneral(final Class<? extends Activity> activityToOpen , Bundle parameters)
Intent intent = new Intent(getBaseContext() , activityToOpen);
for (String key : parameters.keySet())
String params_key = key;
String params_value = parameters.get(key).toString();
// to bundle parameters based on type
intent.putExtra(params_key ,params_value);

startActivity(intent);


//Calling
Bundle data = new Bundle();
data.putString("key1" , "value1");
data.putString("key2" , "value2");
startActivityGeneral(Main2Activity.class , data);
//startActivityGeneral(Main3Activity.class , data);


For adjustable amount of extras with different variables - Use Bundle






share|improve this answer























  • What is the use of the colon in the for() loop?

    – Lasse
    Mar 7 at 10:31











  • That is a "for each loop"/ "enhanced for loop".

    – Ravi
    Mar 7 at 14:16


















0














You can create something like this.



public void setIntent() 
Intent intent = new Intent(YourActivity.this, ActivityToGo.class);
intent.putExtra(key, "test");
startActivity(intent);



And then only you call this method wherever you want.






share|improve this answer






























    0














    your idea is correct but you should pass nameActivity.class as parameter



     setIntent(nameActivity.class,"key","hello");
    ************************************************
    public void setIntent(Class to, String key, String string) {
    Intent intent = new Intent(this, to);
    intent.putExtra(key, string);
    startActivity(intent);





    share|improve this answer






















      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55031876%2fhow-to-create-an-intent-method%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














       // Generalized method
      private void startActivityGeneral(final Class<? extends Activity> activityToOpen , Bundle parameters)
      Intent intent = new Intent(getBaseContext() , activityToOpen);
      for (String key : parameters.keySet())
      String params_key = key;
      String params_value = parameters.get(key).toString();
      // to bundle parameters based on type
      intent.putExtra(params_key ,params_value);

      startActivity(intent);


      //Calling
      Bundle data = new Bundle();
      data.putString("key1" , "value1");
      data.putString("key2" , "value2");
      startActivityGeneral(Main2Activity.class , data);
      //startActivityGeneral(Main3Activity.class , data);


      For adjustable amount of extras with different variables - Use Bundle






      share|improve this answer























      • What is the use of the colon in the for() loop?

        – Lasse
        Mar 7 at 10:31











      • That is a "for each loop"/ "enhanced for loop".

        – Ravi
        Mar 7 at 14:16















      0














       // Generalized method
      private void startActivityGeneral(final Class<? extends Activity> activityToOpen , Bundle parameters)
      Intent intent = new Intent(getBaseContext() , activityToOpen);
      for (String key : parameters.keySet())
      String params_key = key;
      String params_value = parameters.get(key).toString();
      // to bundle parameters based on type
      intent.putExtra(params_key ,params_value);

      startActivity(intent);


      //Calling
      Bundle data = new Bundle();
      data.putString("key1" , "value1");
      data.putString("key2" , "value2");
      startActivityGeneral(Main2Activity.class , data);
      //startActivityGeneral(Main3Activity.class , data);


      For adjustable amount of extras with different variables - Use Bundle






      share|improve this answer























      • What is the use of the colon in the for() loop?

        – Lasse
        Mar 7 at 10:31











      • That is a "for each loop"/ "enhanced for loop".

        – Ravi
        Mar 7 at 14:16













      0












      0








      0







       // Generalized method
      private void startActivityGeneral(final Class<? extends Activity> activityToOpen , Bundle parameters)
      Intent intent = new Intent(getBaseContext() , activityToOpen);
      for (String key : parameters.keySet())
      String params_key = key;
      String params_value = parameters.get(key).toString();
      // to bundle parameters based on type
      intent.putExtra(params_key ,params_value);

      startActivity(intent);


      //Calling
      Bundle data = new Bundle();
      data.putString("key1" , "value1");
      data.putString("key2" , "value2");
      startActivityGeneral(Main2Activity.class , data);
      //startActivityGeneral(Main3Activity.class , data);


      For adjustable amount of extras with different variables - Use Bundle






      share|improve this answer













       // Generalized method
      private void startActivityGeneral(final Class<? extends Activity> activityToOpen , Bundle parameters)
      Intent intent = new Intent(getBaseContext() , activityToOpen);
      for (String key : parameters.keySet())
      String params_key = key;
      String params_value = parameters.get(key).toString();
      // to bundle parameters based on type
      intent.putExtra(params_key ,params_value);

      startActivity(intent);


      //Calling
      Bundle data = new Bundle();
      data.putString("key1" , "value1");
      data.putString("key2" , "value2");
      startActivityGeneral(Main2Activity.class , data);
      //startActivityGeneral(Main3Activity.class , data);


      For adjustable amount of extras with different variables - Use Bundle







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Mar 6 at 21:09









      RaviRavi

      345213




      345213












      • What is the use of the colon in the for() loop?

        – Lasse
        Mar 7 at 10:31











      • That is a "for each loop"/ "enhanced for loop".

        – Ravi
        Mar 7 at 14:16

















      • What is the use of the colon in the for() loop?

        – Lasse
        Mar 7 at 10:31











      • That is a "for each loop"/ "enhanced for loop".

        – Ravi
        Mar 7 at 14:16
















      What is the use of the colon in the for() loop?

      – Lasse
      Mar 7 at 10:31





      What is the use of the colon in the for() loop?

      – Lasse
      Mar 7 at 10:31













      That is a "for each loop"/ "enhanced for loop".

      – Ravi
      Mar 7 at 14:16





      That is a "for each loop"/ "enhanced for loop".

      – Ravi
      Mar 7 at 14:16













      0














      You can create something like this.



      public void setIntent() 
      Intent intent = new Intent(YourActivity.this, ActivityToGo.class);
      intent.putExtra(key, "test");
      startActivity(intent);



      And then only you call this method wherever you want.






      share|improve this answer



























        0














        You can create something like this.



        public void setIntent() 
        Intent intent = new Intent(YourActivity.this, ActivityToGo.class);
        intent.putExtra(key, "test");
        startActivity(intent);



        And then only you call this method wherever you want.






        share|improve this answer

























          0












          0








          0







          You can create something like this.



          public void setIntent() 
          Intent intent = new Intent(YourActivity.this, ActivityToGo.class);
          intent.putExtra(key, "test");
          startActivity(intent);



          And then only you call this method wherever you want.






          share|improve this answer













          You can create something like this.



          public void setIntent() 
          Intent intent = new Intent(YourActivity.this, ActivityToGo.class);
          intent.putExtra(key, "test");
          startActivity(intent);



          And then only you call this method wherever you want.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 6 at 20:55









          SpritzigSpritzig

          1591316




          1591316





















              0














              your idea is correct but you should pass nameActivity.class as parameter



               setIntent(nameActivity.class,"key","hello");
              ************************************************
              public void setIntent(Class to, String key, String string) {
              Intent intent = new Intent(this, to);
              intent.putExtra(key, string);
              startActivity(intent);





              share|improve this answer



























                0














                your idea is correct but you should pass nameActivity.class as parameter



                 setIntent(nameActivity.class,"key","hello");
                ************************************************
                public void setIntent(Class to, String key, String string) {
                Intent intent = new Intent(this, to);
                intent.putExtra(key, string);
                startActivity(intent);





                share|improve this answer

























                  0












                  0








                  0







                  your idea is correct but you should pass nameActivity.class as parameter



                   setIntent(nameActivity.class,"key","hello");
                  ************************************************
                  public void setIntent(Class to, String key, String string) {
                  Intent intent = new Intent(this, to);
                  intent.putExtra(key, string);
                  startActivity(intent);





                  share|improve this answer













                  your idea is correct but you should pass nameActivity.class as parameter



                   setIntent(nameActivity.class,"key","hello");
                  ************************************************
                  public void setIntent(Class to, String key, String string) {
                  Intent intent = new Intent(this, to);
                  intent.putExtra(key, string);
                  startActivity(intent);






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 6 at 21:34









                  Missaoui baha eddineMissaoui baha eddine

                  1




                  1



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55031876%2fhow-to-create-an-intent-method%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      1928 у кіно

                      Захаров Федір Захарович

                      Ель Греко