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 check internet access on Android? InetAddress never times out

If the device is in airplane mode (or presumably in other situations where there’s no available network), cm.getActiveNetworkInfo() will be null, so you need to add a null check. Modified (Eddie’s solution) below: public boolean isOnline() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); return netInfo != null && netInfo.isConnectedOrConnecting(); } Also add … Read more

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 can I avoid concurrency problems when using SQLite on Android?

Inserts, updates, deletes and reads are generally OK from multiple threads, but Brad’s answer is not correct. You have to be careful with how you create your connections and use them. There are situations where your update calls will fail, even if your database doesn’t get corrupted. The basic answer. The SqliteOpenHelper object holds on … Read more

Detect whether there is an Internet connection available on Android [duplicate]

The getActiveNetworkInfo() method of ConnectivityManager returns a NetworkInfo instance representing the first connected network interface it can find or null if none of the interfaces are connected. Checking if this method returns null should be enough to tell if an internet connection is available or not. private boolean isNetworkAvailable() { ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); … Read more

Standard Android Button with a different color

I discovered that this can all be done in one file fairly easily. Put something like the following code in a file named custom_button.xml and then set background=”@drawable/custom_button” in your button view: <?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:state_pressed=”true” > <shape> <gradient android:startColor=”@color/yellow1″ android:endColor=”@color/yellow2″ android:angle=”270″ /> <stroke android:width=”3dp” android:color=”@color/grey05″ /> <corners android:radius=”3dp” /> <padding android:left=”10dp” … Read more

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