i passing data keyword search with intent for get result in other activity. the keyword search use to search data from database sqlite, but i can't display the result with textView, there is no error in logcat. what problem with my code?
there is my code to display output
OutputSuccess.java
package com.mjusuf.halal;
import android.support.v7.app.ActionBarActivity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class OutputSuccess extends ActionBarActivity {
// Objects And Variables
private String select;
// User Information Variables
String c2, c3, c4, c5, c6;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_outputsuccess);
TextView certificate_no = (TextView) findViewById(R.id.textView3);
TextView valid_from = (TextView) findViewById(R.id.textView6);
TextView valid_to = (TextView) findViewById(R.id.textView9);
TextView company = (TextView) findViewById(R.id.textView12);
TextView product_name = (TextView) findViewById(R.id.textView15);
// name.setText(getIntent().getExtras().getString("search"));
DatabaseHandler db = new DatabaseHandler(this);
SQLiteDatabase db1 = db.getReadableDatabase();
select = "SELECT * FROM certificate WHERE Certificate_No='"
+ getIntent().getExtras().getString("search") + "'";
Cursor c1 = db1.rawQuery(select, null);
if (c1 != null && c1.moveToFirst())
do {
certificate_no.setText(c1.getString(c1.getColumnIndex("Certificate_No")));
valid_from.setText(c1.getString(c1.getColumnIndex("Valid_From")));
valid_to.setText(c1.getString(c1.getColumnIndex("Valid_To")));
company.setText(c1.getString(c1.getColumnIndex("Company")));
product_name.setText(c1.getString(c1.getColumnIndex("Product_Name")));
} while (c1.moveToNext());
};
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.output_success, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Related
This question already has answers here:
How to use this boolean in an if statement?
(8 answers)
Closed 6 years ago.
here is my code
i try his solution but it didnt work
package com.FF_studio.psp_rd_lite_1;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class LoginActivity extends Activity {
EditText urn,pwd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
}
public void login(View v) {
urn = (EditText)findViewById(R.id.username);
pwd = (EditText)findViewById(R.id.password);
String site = "";
String error = "用戶名稱或密碼錯誤,請重新輸入";
String url = "";
String ans = "admin";
String ans1 = "rico1010";
urn.getText().toString();
pwd.getText().toString();
if(urn = ans) //error occur here
url = "";
else
Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.login, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Several problems here.
urn.getText().toString();
doesn't really do anything. You need to assign a variable to it to make use of it.
String urnString = urn.getText().toString();
Second, = is an assignment operator and not a comparison operator. You would want == to compare.
Third == is not the right way to compare Strings in Java you want .equals()
Here's my code so far:
package com.alibdeir.database;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.parse.GetCallback;
import com.parse.Parse;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.SaveCallback;
import com.parse.ParseException;
public class MainActivity extends AppCompatActivity {
TextView output;
Button increase;
int currentInt;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Parse.initialize(this, "QeaC0wiXsL9MyRbLaQPBWA9QzXim****lE7b8HjP", "kDjoZVRu4OyWOGxPtPjh7f*bXKFxp**VYO7g2qqd");
output = (TextView) findViewById(R.id.output);
increase = (Button) findViewById(R.id.increase);
// try {
// Parse.initialize(this, "QeaC0wiXsL9MyRbLaQPBWA9QzXimS7vPlE7b8HjP", "QeaC0wiXsL9MyRbLaQPBWA9QzXimS7vPlE7b8HjP");
// ParseQuery uptodatequery = new ParseQuery("refresh");
// ParseObject refresh = uptodatequery.get("n6zA3CHxGx");
// output.setText(refresh.toString());
// } catch (com.parse.ParseException e1) {
// e1.printStackTrace();
// }
}
public void increase(View v) {
currentInt = Integer.parseInt(output.getText().toString());
output.setText(currentInt + 1 + "");
// try {
// Parse.initialize(this, "QeaC0wiXsL9MyRbLaQPBWA9QzXimS7vPlE7b8HjP", "QeaC0wiXsL9MyRbLaQPBWA9QzXimS7vPlE7b8HjP");
// output = (TextView) findViewById(R.id.output);
// increase = (Button) findViewById(R.id.increase);
// ParseQuery query = new ParseQuery("int");
// ParseObject upload = query.get("n6zA3CHxGx");
// upload.increment("n6zA3CHxGx",currentInt);
// upload.saveInBackground();
// } catch (com.parse.ParseException e1) {
// e1.printStackTrace();
// }
ParseQuery<ParseObject> currentNumber = ParseQuery.getQuery("currentNumber");
// Retrieve the object by id
currentNumber.getInBackground("n6zA3CHxGx", new GetCallback<ParseObject>() {
public void done(ParseObject currentNumber, ParseException e) {
if (e == null) {
// Now let's update it with some new data. In this case, only cheatMode and score
// will get sent to the Parse Cloud. playerName hasn't changed.
int currentInt = currentNumber.getInt("currentNumber");
currentNumber.put("currentNumber", currentInt + 1);
currentNumber.saveEventually();
}
}
});
}
// #Override
// public boolean onCreateOptionsMenu(Menu menu) {
// // Inflate the menu; this adds items to the action bar if it is present.
// getMenuInflater().inflate(R.menu.menu_main, menu);
// return true;
// }
//
// #Override
// public boolean onOptionsItemSelected(MenuItem item) {
// // Handle action bar item clicks here. The action bar will
// // automatically handle clicks an the Home/Up button, so long
// // as you specify a parent activity in AndroidManifest.xml.
// int id = item.getItemId();
//
// //noinspection SimplifiableIfStatement
// if (id == R.id.action_settings) {
// return true;
// }
//
// return super.onOptionsItemSelected(item);
// }
}
I tried so many stuff, including the ones I've commented.
public void increase
is my onclick method for a button. When you click that button, the textview output changes, the int, which is currentInt, gets a +1. What I want to do is onClick of the button I also want it to update the int in the database. How can I do that?
You can perform an atomic increment provided by Parse.
currentNumber.increment("currentNumber");
currentNumber.saveInBackground();
I have an application that populates a ListView with user input data from another Activity ; however, whenever I enter that data into the second Activity then return to the ListView activity I see it populated with the values I entered. But, if I return to the second activity again, enter the values, and go back to the ListView activity, I see the new values updated but the old ones have disappeared.
Now, I don't know if I'm not updating the listview correctly or if I need to use sqlite databases to store this data or shared preferences in order to update the listview to new data while containing the previous information.
Thanks for any help.
ListActivity.java
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.personalproject.peter.timerapp.TestingForAlarmData.TestAlarm;
import java.util.ArrayList;
import java.util.List;
public class ListOfAlarms extends ActionBarActivity {
private static final int RESULT = 1000;
List<TestAlarm> alarms = new ArrayList<>();
String title;
int totalTime;
ListView listOfAlarms;
ArrayAdapter<TestAlarm> alarmArrayAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_of_alarms);
final TextView emptyViewForList = (TextView) findViewById(R.id.emptyTextViewForList);
listOfAlarms = (ListView) findViewById(R.id.listView);
alarmArrayAdapter = new ArrayAdapter<>(this,android.R.layout.simple_list_item_1, alarms);
listOfAlarms.setAdapter(alarmArrayAdapter);
// if(listOfAlarms.getCount() <= 0){
// emptyViewForList.setText("No Alarms Currently Available");
// listOfAlarms.setEmptyView(emptyViewForList);
// }
listOfAlarms.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
alarms.get(position);
Intent clockDownActivity = new Intent(ListOfAlarms.this, CountDownAct.class);
clockDownActivity.putExtra("Title", title);
clockDownActivity.putExtra("totalTime", totalTime);
startActivity(clockDownActivity);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_list_of_alarms, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void goToFillOut(View view) {
Intent goingToFillOut = new Intent(this, Test.class);
startActivityForResult(goingToFillOut, RESULT);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == RESULT && resultCode == RESULT_OK){
title = data.getStringExtra("title");
totalTime = data.getIntExtra("totalTime", 0);
alarms.add(new TestAlarm(title, totalTime));
alarmArrayAdapter.notifyDataSetChanged();
}
}
}
SecondActivity
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Test extends ActionBarActivity {
private static final String LOGTAG = "Test.class";
private static final long timeInterval = 1000;
private Button complete;
private EditText titleEditText;
private EditText hourEditText;
private EditText minuteEditText;
private EditText secondEditText;
public static int hour;
public static int minute;
public static int second;
public static String title;
public int actualTimeFiniliazedInMilliSeconds;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
titleEditText = (EditText) findViewById(R.id.titleEditText);
hourEditText = (EditText) findViewById(R.id.hourEditText);
minuteEditText = (EditText) findViewById(R.id.minuteEditText);
secondEditText = (EditText) findViewById(R.id.secondEditText);
complete = (Button) findViewById(R.id.completeButton);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void saveTimer(View view) {
if(titleEditText.getText().toString().isEmpty() || hourEditText.getText().toString().isEmpty()
|| minuteEditText.getText().toString().isEmpty() || secondEditText.getText().toString().isEmpty()) {
Toast.makeText(this, "Oops you forgot one", Toast.LENGTH_LONG).show();
return;
}
// complete.setVisibility(View.GONE);
title = titleEditText.getText().toString();
hour = Integer.parseInt(hourEditText.getText().toString().trim());
minute = Integer.parseInt(minuteEditText.getText().toString().trim());
second = Integer.parseInt(secondEditText.getText().toString().trim());
hour *= 3600000;
minute *= 60000;
second *= 1000;
actualTimeFiniliazedInMilliSeconds = hour + minute + second;
Intent intent = new Intent(Test.this, ListOfAlarms.class);
intent.putExtra("title", title);
intent.putExtra("totalTime", actualTimeFiniliazedInMilliSeconds);
setResult(RESULT_OK, intent);
finish();
}
}
Alarm.java
public class TestAlarm {
public String title;
public int totalTime;
public TestAlarm (String title, int totalTime) {
this.title = title;
this.totalTime = totalTime;
}
#Override
public String toString() {
return title;
}
}
It seems like you are replacing new list in listview rather to updating old list of listview.
When you come first time on activity A, you should create one global array list where you add all items which are added by user.
Now, when user go on Activity B and add any item, you should carry out value back to Activity A and add that item in list.
After adding that in list, you should notify data to Adapter. So, here your list will have 2 items and it will show on Activity A 2 items.
im trying to make an app in Android Studio that recordes gps locations and im using SQLite for the database. im a beginner on java/android studio and have taken a crash course on how to make a project through vids on youtube.
i've placed the create database code on a function, and is being called on create. im able to build the program with no errors but i keep getting the "Database Missing" toast. am i missing something?
#MainActivity.java
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import java.io.File;
public class MainActivity extends ActionBarActivity {
SQLiteDatabase recordedDB = null;
GPSLocation gps;
int ReadingCount = 0;
float oldAcc,newAcc;
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ReAcquireData();
CreateDB();
}
public void Save(View view) {
}
public void ReAcquireData(View view) {
ReAcquireData();
}
public void ReAcquireData(){
final TextView tvLat = (TextView) findViewById(R.id.tvLat);
final TextView tvLong = (TextView) findViewById(R.id.tvLong);
final TextView tvAcc = (TextView) findViewById(R.id.tvAcc);
final TextView tvRead = (TextView) findViewById(R.id.tvReadings);
gps = new GPSLocation(MainActivity.this);
if (gps.canGetLocation()) {
ReadingCount++;
if (ReadingCount == 1) {
oldAcc = gps.getAccuracy();
tvLat.setText(Double.toString(gps.getLatitude()));
tvLong.setText(Double.toString(gps.getLongitude()));
tvAcc.setText(Float.toString(oldAcc) + "m");
}
else {
newAcc = gps.getAccuracy();
if (newAcc < oldAcc) {
oldAcc = newAcc;
tvLat.setText(Double.toString(gps.getLatitude()));
tvLong.setText(Double.toString(gps.getLongitude()));
tvAcc.setText(Float.toString(oldAcc) + "m");
}
}
tvRead.setText(Integer.toString(ReadingCount));
} else gps.showSettingsAlert();
}
public void CreateDB(){
try{
recordedDB = this.openOrCreateDatabase("GeoLocator",MODE_PRIVATE,null);
recordedDB.execSQL("CREATE TABLE IF NOT EXISTS database ("+
"entry integer primary key,"+
"operatorID VARCHAR,"+
"municipality VARCHAR,"+
"barangay VARCHAR,"+
"longitude DOUBLE,"+
"latitude DOUBLE,"+
"accuracy FLOAT,"+
"landcover VARCHAR,"+
"remarks VARCHAR);"
);
File database = getApplicationContext().getDatabasePath("GeoLocator.db");
if(database.exists())
Toast.makeText(this,"Database Exists", Toast.LENGTH_SHORT).show();
else
Toast.makeText(this,"Database Missing", Toast.LENGTH_SHORT).show();
} catch(Exception e){
Log.e("GeoLocator ERROR","Error Creating Database");
}
}
}
Just make sure that you pass in the same string name you used to create the database to the getDatbasePath() method.
Replace
File database = getApplicationContext().getDatabasePath("GeoLocator.db");
With
File database = getApplicationContext().getDatabasePath("GeoLocator");
I work simple android app for sending sms. I have 2 activities. One is main for sending 2 different messages with 2 different content but messages send to same number. On secund activity i have 3 fields: one is for input number to send messages, and other two are for message content. When I click save button app save user input and go back to main activity. And here start my problem. How can i send users input for number to send messages and messages content to main activity to send sms with saved user input? I am totally beginner with android developing so please help! Here is my MainActivity.java:
package com.example.davor.light;
import android.content.Intent; import
android.support.v7.app.ActionBarActivity; import android.os.Bundle;
import android.telephony.SmsManager; import
android.telephony.SmsMessage; import android.view.Menu; import
android.view.MenuItem; import android.view.View; import
android.widget.Button; import android.widget.ImageView; import
android.widget.TextView; import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// GUMBI INFORMACIJE
Button ukljuci = (Button) findViewById(R.id.ukljuci);
Button iskljuci = (Button) findViewById(R.id.iskljuci);
Button postavke = (Button) findViewById(R.id.postavke);
final ImageView slika = (ImageView) findViewById(R.id.slika);
// INFORMACIJA O PORUCI
final String broj = "097";
final String ukljuciPoruka = "Uključi";
final String iskljuciPoruka = "Isključi";
// KLIK NA GUMB ISKLJUČI
iskljuci.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(broj, null, iskljuciPoruka, null, null);
Toast.makeText(getApplicationContext(), "Isključeno! poslano na broj " + broj, Toast.LENGTH_LONG).show();
slika.setImageResource(R.drawable.off);
} catch (Exception e) {
Toast.makeText(getApplicationContext(),"Nemoguće isključiti!",Toast.LENGTH_LONG).show();
}
}
});
postavke.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent PostavkeActivity = new Intent(MainActivity.this,
Postavke.class);
startActivity(PostavkeActivity);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
} }
And here is code for my second activity from witch I want to pull users input to MainActivity:
package com.example.davor.light;
import android.app.Activity; import android.content.Intent; import
android.content.SharedPreferences; import
android.preference.PreferenceManager; import
android.support.v7.app.ActionBarActivity; import android.os.Bundle;
import android.view.Menu; import android.view.MenuItem; import
android.view.View; import android.widget.Button; import
android.widget.EditText; import android.widget.TextView; import
android.widget.Toast;
public class Postavke extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_postavke);
gumbZaPovratak();
SharedPreferences loadSettings = PreferenceManager.getDefaultSharedPreferences(this);
String ucitajBroj = loadSettings.getString("spremiBroj", "");
String ucitajUkljuci = loadSettings.getString("spremiUkljuci", "");
String ucitajIskljuci = loadSettings.getString("spremiIskljuci", "");
final EditText postavkeBroj = (EditText) findViewById(R.id.postavkeBroj);
postavkeBroj.setText(ucitajBroj);
final EditText postavkeUkljuci = (EditText) findViewById(R.id.postavkeUkljuci);
postavkeUkljuci.setText(ucitajUkljuci);
final EditText postavkeIskljuci = (EditText) findViewById(R.id.postavkeIskljuci);
postavkeIskljuci.setText(ucitajIskljuci);
Button spremi = (Button) findViewById(R.id.postavkeSpremi);
spremi.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v){
spremiPostavke("spremiBroj", postavkeBroj.getText().toString());
spremiPostavke("spremiUkljuci", postavkeUkljuci.getText().toString());
spremiPostavke("spremiIskljuci", postavkeIskljuci.getText().toString());
Toast.makeText(getApplicationContext(), "Spremljeno", Toast.LENGTH_LONG).show();
finish();
}
});
}
private void postavkeBroj() {
EditText postavkeBroj = (EditText) findViewById(R.id.postavkeBroj);
}
private void spremiPostavke (String ključ, String vrijednost) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(ključ, vrijednost);
editor.commit();
}
private void gumbZaPovratak(){
Button nazad = (Button) findViewById(R.id.nazad);
nazad.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_postavke, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
} }
You can use startActivityForResult()
You can refer this link:
http://hmkcode.com/android-startactivityforresult/
In Activity1
Intent myIntent = new Intent(this,Activity2.class);
myIntent.putExtra("var", variable_to_pass);
startActivity(myIntent);
In Activity2
Bundle extras = getIntent().getExtras();
if (extras != null) {
intentExtra = extras.getString("var"); // retrieving variable
}
You can add data to an intent like this :
String messageContent = (EditText) findViewById(yourMessageContentId).getText().toString();
String messageNumber = (EditText) findViewById(yourMessageNumberId).getText().toString();
intent.putExtra("com.example.davor.light.MESSAGE_CONTENT", messageContent);
intent.putExtra("com.example.davor.light.MESSAGE_NUMBER", messageNumber);
And then get it on the MainActivity :
Intent intent = getIntent();
String messageNumber = intent.getStringExtra("com.example.davor.light.MESSAGE_NUMBER");
String messageContent = intent.getStringExtra("com.example.davor.light.MESSAGE_CONTENT");
you can send information from one activity to other activity like bellow
Intent postavkeActivity = new Intent(MainActivity.this,
Postavke.class);
Bundle bundle=new Bundle();
bundle.putString(|"messageKey1", "message content1");
bundle.putString(|"messageKey2", "message content2");
postavkeActivity.putExtras(bundle);
startActivity(PostavkeActivity);
in main activity get bundle data like bellow
Bundle b=getIntent.getExtras();
String smsContent=b.getString("messageKey1");