{"id":13662,"date":"2020-01-21T12:22:51","date_gmt":"2020-01-21T12:22:51","guid":{"rendered":"https:\/\/ittutorial.org\/?p=13662"},"modified":"2020-01-23T13:15:11","modified_gmt":"2020-01-23T13:15:11","slug":"android-programming-10-sending-parameters-between-two-activities","status":"publish","type":"post","link":"https:\/\/ittutorial.org\/android-programming-10-sending-parameters-between-two-activities\/","title":{"rendered":"Android Programming -10 Sending Parameters Between Two Activities"},"content":{"rendered":"<p>Hi guys in this tutorial \u00a0we will talk about sending and receiving parameters between two activities.<\/p>\n<p>In my previous tutorial, I talked about the transition between application page. If you have not read it yet, I recommend you read it first.<\/p>\n<p><a href=\"https:\/\/ittutorial.org\/android-programming-9-switching-between-application-pages\/\">https:\/\/ittutorial.org\/android-programming-9-switching-between-application-pages\/<\/a><\/p>\n<pre>login.setOnClickListener(new View.OnClickListener() {\r\n\u00a0\u00a0\u00a0 @Override\r\n\u00a0\u00a0\u00a0 public void onClick(View v) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (kullanici_adi.getText()==\"kubrahebes\" &amp;&amp; sifre.getText()==\"12345\") {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Intent yeni_sayfa =new Intent(MainActivity.this, Anasayfa.Activity);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 yeni_sayfa.putExtra(\"isim\", \"kubraa\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 startactivity(yeni_sayfa);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 else {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 mesaj.setText(\"Ba\u015far\u0131s\u0131z Giri\u015f !!!\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 }\r\n});\r\n\r\n<\/pre>\n<p>since we have examined the code in detail previous article, I only share the codes in the\u00a0 onclick method this day. if username and password are correct they will pass to the new page with intent method, we saw it in the previous lesson. today we will learn how sending parameters with intent. We can do this with putExtra method. The putExtra method works as key value. The first parameter we give to this method is key and the second parameter creates value. Key value is very important for us. Because we will get the value we send over the key value on the other page.<\/p>\n<p>Just write this one line of code on the current page.\u00a0 We also need to write code on the new page. It is as follows;<\/p>\n<pre>package com.example.mac.makale;\r\n\r\nimport android.content.Intent;\r\nimport android.os.Bundle;\r\n\r\npublic class YeniSayfaActivity extends AppCompatActivity{\r\n\r\n@Override\r\n\u00a0\u00a0\u00a0 protected void onCreate(Bundle savedInstanceState) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 super.onCreate(savedInstanceState);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 setContentView(R.layout.activity_yeni_sayfa);\r\n\r\nIntent intent = getIntent();\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 final String ad = intent.getStringExtra(\"isim\");\r\n\r\nToast.makeText(this, ad, Toast.LENGTH_SHORT).show();\r\n\r\n}<\/pre>\n<p>on this activity class we first import our libraries.\u00a0 Then we name\u00a0 our class name and extended it from the Activity class. After that we start to our codes in the oncreate method. We get the value from the other page again via intent class.\u00a0 For this reason we create an object of intent class.\u00a0 since the value from other page is a string, we define a variabla which type is string. With the intent class&#8217;s getStringExtra method, we capture the value from the other page and assign it to the variable we created.<\/p>\n<p style=\"margin: 0in;font-family: Calibri;font-size: 11.0pt\">Of course for the capture the correct value, we have to specify the key value when using this method. otherwise, the program does not know which value totake during compilation and gets an error.<\/p>\n<p style=\"margin: 0in;font-family: Calibri;font-size: 11.0pt\">Finally, we show the value from the other page with the message Toast.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi guys in this tutorial \u00a0we will talk about sending and receiving parameters between two activities. In my previous tutorial, I talked about the transition between application page. If you have not read it yet, I recommend you read it first. https:\/\/ittutorial.org\/android-programming-9-switching-between-application-pages\/ login.setOnClickListener(new View.OnClickListener() { \u00a0\u00a0\u00a0 @Override \u00a0\u00a0\u00a0 public void onClick(View v) { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if &hellip;<\/p>\n","protected":false},"author":44,"featured_media":8094,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-13662","post","type-post","status-publish","format-standard","has-post-thumbnail","","category-android"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/04\/featured-860x280.png","jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/13662","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/users\/44"}],"replies":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/comments?post=13662"}],"version-history":[{"count":1,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/13662\/revisions"}],"predecessor-version":[{"id":13663,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/13662\/revisions\/13663"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/media\/8094"}],"wp:attachment":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/media?parent=13662"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/categories?post=13662"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/tags?post=13662"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}