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

Why fragments, and when to use fragments instead of activities?

#1 & #2 what are the purposes of using a fragment & what are the advantages and disadvantages of using fragments compared to using activities/views/layouts? Fragments are Android’s solution to creating reusable user interfaces. You can achieve some of the same things using activities and layouts (for example by using includes). However; fragments are wired … Read more

Fullscreen Activity in Android?

You can do it programatically: public class ActivityName extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // remove title requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.main); } } Or you can do it via your AndroidManifest.xml file: <activity android:name=”.ActivityName” android:label=”@string/app_name” android:theme=”@android:style/Theme.NoTitleBar.Fullscreen”/> Edit: If you are using AppCompatActivity then you need to add new theme <style name=”Theme.AppCompat.Light.NoActionBar.FullScreen” … 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”/>

Get root view from current activity

If you need root view of your activity (so you can add your contents there) use findViewById(android.R.id.content).getRootView() Also it was reported that on some devices you have to use getWindow().getDecorView().findViewById(android.R.id.content) instead. Please note that as Booger reported, this may be behind navigation bar (with back button etc.) on some devices (but it seems on most … Read more

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

How to send an object from one Android Activity to another using Intents?

If you’re just passing objects around then Parcelable was designed for this. It requires a little more effort to use than using Java’s native serialization, but it’s way faster (and I mean way, WAY faster). From the docs, a simple example for how to implement is: // simple class that just has one member property … Read more

onActivityResult is not being called in Fragment

The hosting activity overrides onActivityResult(), but it did not make a call to super.onActivityResult() for unhandled result codes. Apparently, even though the fragment is the one making the startActivityForResult() call, the activity gets the first shot at handling the result. This makes sense when you consider the modularity of fragments. Once I implemented super.onActivityResult() for … Read more

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