How to start new activity on button click

In an Android application, how do you start a new activity (GUI) when a button in another activity is clicked, and how do you pass data between these two activities? 27 s 27 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 … Read more

Dilemma: when to use Fragments vs Activities:

I know that Activities are designed to represent a single screen of my application, while Fragments are designed to be reusable UI layouts with logic embedded inside of them. Until not long ago, I developed an application as it said that they should be developed. I created an Activity to represent a screen of my … Read more

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

I am trying to work on sending an object of my customer class from one Activity and display it in another Activity. The code for the customer class: public class Customer { private String firstName, lastName, Address; int Age; public Customer(String fname, String lname, int age, String address) { firstName = fname; lastName = lname; … Read more

onActivityResult is not being called in Fragment

The activity hosting this fragment has its onActivityResult called when the camera activity returns. My fragment starts an activity for a result with the intent sent for the camera to take a picture. The picture application loads fine, takes a picture, and returns. The onActivityResult however is never hit. I’ve set breakpoints, but nothing is … Read more

How do I create a transparent Activity on Android?

I want to create a transparent Activity on top of another activity. How can I achieve this? 24 s 24 Add the following style in your res/values/styles.xml file (if you don’t have one, create it.) Here’s a complete file: <?xml version=”1.0″ encoding=”utf-8″?> <resources> <style name=”Theme.Transparent” parent=”android:Theme”> <item name=”android:windowIsTranslucent”>true</item> <item name=”android:windowBackground”>@android:color/transparent</item> <item name=”android:windowContentOverlay”>@null</item> <item name=”android:windowNoTitle”>true</item> <item … Read more

How to manage startActivityForResult on Android

In my activity, I’m calling a second activity from the main activity by startActivityForResult. In my second activity, there are some methods that finish this activity (maybe without a result), however, just one of them returns a result. For example, from the main activity, I call a second one. In this activity, I’m checking some … Read more