Android: Go back to previous activity

Android activities are stored in the activity stack. Going back to a previous activity could mean two things. You opened the new activity from another activity with startActivityForResult. In that case you can just call the finishActivity() function from your code and it’ll take you back to the previous activity. Keep track of the activity … Read more

What is an Android PendingIntent?

A PendingIntent is a token that you give to a foreign application (e.g. NotificationManager, AlarmManager, Home Screen AppWidgetManager, or other 3rd party applications), which allows the foreign application to use your application’s permissions to execute a predefined piece of code. If you give the foreign application an Intent, it will execute your Intent with its … Read more

How to open the Google Play Store directly from my Android application?

You can do this using the market:// prefix. Java final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(“market://details?id=” + appPackageName))); } catch (android.content.ActivityNotFoundException anfe) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(“https://play.google.com/store/apps/details?id=” + appPackageName))); } Kotlin try { startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(“market://details?id=$packageName”))) } catch (e: ActivityNotFoundException) { startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(“https://play.google.com/store/apps/details?id=$packageName”))) } We use a … Read more

Send Email Intent

UPDATE Official approach: public void composeEmail(String[] addresses, String subject) { Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setData(Uri.parse(“mailto:”)); // only email apps should handle this intent.putExtra(Intent.EXTRA_EMAIL, addresses); intent.putExtra(Intent.EXTRA_SUBJECT, subject); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } } Ref link OLD ANSWER The accepted answer doesn’t work on the 4.1.2. This should work on all platforms: Intent emailIntent … Read more

Sending Email in Android using JavaMail API without using the default/built-in app

Send e-mail in Android using the JavaMail API using Gmail authentication. Steps to create a sample Project: MailSenderActivity.java: public class MailSenderActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final Button send = (Button) this.findViewById(R.id.send); send.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { GMailSender sender = new GMailSender(“username@gmail.com”, “password”); sender.sendMail(“This … Read more

How to start new activity on button click

Easy. Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class); myIntent.putExtra(“key”, value); //Optional parameters CurrentActivity.this.startActivity(myIntent); Extras are retrieved on the other side via: @Override protected void onCreate(Bundle savedInstanceState) { Intent intent = getIntent(); String value = intent.getStringExtra(“key”); //if it’s a string you stored. } Don’t forget to add your new activity in the AndroidManifest.xml: <activity android:label=”@string/app_name” android:name=”NextActivity”/>

How to pass an object from one activity to another on Android

One option could be letting your custom class implement the Serializable interface and then you can pass object instances in the intent extra using the putExtra(Serializable..) variant of the Intent#putExtra() method. Actual Code: In Your Custom Model/Object Class: public class YourClass implements Serializable { At other class where using the Custom Model/Class: //To pass: intent.putExtra(“KEY_NAME”, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)