I have two Activity. I want pass LatLng pass to another Activity.
This code in first Activity:
public void testclick (View v){
Intent intent = new Intent(TestActivity.this, MainMenu.class);
intent.putExtra("lat", "58.37");
intent.putExtra("lan", "37.95");
startActivity(intent);
}
What I must write in another Activity to get LaTLng?
Intent intent = new Intent(getApplicationContext(), MainMenu.class);
intent.putExtra("lat", "`58.37`");
intent.putExtra("lan", "37.95")
startActivity(intent)
And MainMenu Activity onCreate() method receive
if(getIntent().getExtras() != null) {
String lat = getIntent().getExtras().getString("lat");
String lan = getIntent().getExtras().getString("lan");
}
Related
Main Activity 2
MAIN ACTIVITY
Android Studio My name is not displaying in second activity after passing through first Activity
In your Main Activity:
Please call intent.putExtra(), before startActivity(). Example:
val intent = Intent(this, NewActivity::class.java)
intent.putExtra("username","Name")
startActivity(intent)
And fetch like that (in Main Activity 2)
val bundle :Bundle?=intent.extras
if (bundle!=null){
val user_name = bundle.getString("username")
}
I noticed that in the 'MainActivity.java' you are starting new activity before passing the string into the intent,
just switch the both lines 30 and 31.
In your MainActivity, you should putExtra before startActivity. Like this:
Intent intent = new Intent(...);
intent.putExtra...;
startActivity(intent);
In your MainActivity, create a new Intent:
String name="abcdef;
Intent i = new Intent(MainActivity.this, MainActivity2.class);
i.putExtra("key",name);
startActivity(i);
Then in the MainActivity2, retrieve those values:
Bundle extras = getIntent().getExtras();
if (extras != null) {
String name = extras.getString("key");
//"key" must match that used in the other activity
}
I want when the player clicks on the imageView the ads should show first if its ready and then go to the next activity
here is my code
FalgQuizImageView.setOnClickListener {
if (mInterstitialAd != null) {
mInterstitialAd?.show(this)
}
mInterstitialAd?.fullScreenContentCallback = object: FullScreenContentCallback() {
override fun onAdDismissedFullScreenContent() {
val intent = Intent(this, QuizQuestionsCar::class.java)
startActivity(intent)
}
override fun onAdFailedToShowFullScreenContent(adError: AdError?) {
val intent = Intent(this, QuizQuestionsCar::class.java)
startActivity(intent)
}
}
}
Here is the error
First parameter on Intent constructor is of type Context, you are passing this which in your case refers to the FullScreenContentCallback object and its not of type Context. To fix this do the following
val intent = Intent(this#YourActivityName, QuizQuestionsCar::class.java)
this#YourActivityName refers to your Activity object, which is a Context
How can I send information from one activity to two activities? I would like to add another intent but I get an error about a null object... My guess is that I also would need to use another spinner for this class but just wondering if there is a short cut?
add_review.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Review.this, Add_Review.class);
String chosenOption = spinner.getSelectedItem().toString();
intent.putExtra("Add a Review for", chosenOption);
startActivity(intent);
finish();
Intent send_information = new Intent(Review.this, PopularMedicalClinic.class);
String chosenOption2 = spinner.getSelectedItem().toString();
intent.putExtra("Name", chosenOption2);
startActivity(send_information);
finish();
}
This is a wrong approach in your code. You are trying to open two activity at a time. After starting first intent you call finish() method. finish() method kill current activity.
Can you explain why you want to open two activity at a time. Then I can suggest you.
Just use another extra putExtra method.
and remove finish() method. it will destroy your activity.
String chosenOption = spinner.getSelectedItem().toString();
String chosenOption2 = spinner.getSelectedItem().toString();
Intent intent = new Intent(Review.this, Add_Review.class);
intent.putExtra("Add_a_Review_for", chosenOption);
intent.putExtra("Name", chosenOption2);
startActivity(intent);
Im trying to connect Navigation Drawer to activity. I already have some Activity that extends AppCompatActivity. but in tutorial, Activity you want to connect navigation drawer should extends Fragments. Is there any way to get around this problem?
#Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.home) {
Intent secIntent = new Intent(this, SecondActivity.class);
startActivity(homeIntent);
} else if (id == R.id.livestream) {
Intent nextIntent = new Intent(this, NextActivity.class);
startActivity(nextIntent);
}
mDrawer = findViewById(R.id.drawer_layout);
mDrawer.closeDrawer(GravityCompat.START);
return true;
}
just use intent for change each activity from navigation drawer, but the consequence of use activity is the navigation is only in activity where navigation is putted, you should use setDisplayHomeAsUpEnabled(true) in action bar to make it easy for back to MainActivity
I want to open a new activity when search filter is clicked in recycler view of android studio.
An open source code may be found here that is given below. It has json file from where we can fetch the search filter item.
https://www.androidhive.info/2017/11/android-recyclerview-with-search-filter-functionality/
Please tell me the code that how we can get to new activity such as hello.xml when hello is being clicked in search filter item.
In my opinion the code should be here in mainactivity.java..
#Override
public void onContactSelected(Contact contact) {
String type = contact.getClass().getName();
if (type.startsWith("Tom")) {
Intent i = new Intent(MainActivity.this, MainActivity.class);
startActivity(i);
} else if (type.startsWith("")) {
Intent intent = new Intent(MainActivity.this, Hello.class);
startActivity(intent);
}
Please help to put my code instead of toast.
public void onContactSelected(Contact contact) {
// TextView name = (TextView) Contact;
if ( contact.getName().toString().equalsIgnoreCase("Tom Hardy"))
{
startActivity(new Intent(MainActivity.this, Hello.class));
finish();
}
else{
Toast.makeText(MainActivity.this, " no activity "+contact.getName(), Toast.LENGTH_SHORT).show();
}
}