Tutorial by Examples: activity

This example will start DestinationActivity from OriginActivity. Here, the Intent constructor takes two parameters: A Context as its first parameter (this is used because the Activity class is a subclass of Context) The Class of the app component to which the system should deliver the Intent (i...
package com.example; import android.os.Bundle; import android.support.annotation.Nullable; import android.util.Log; import android.view.View; import android.view.ViewTreeObserver; public class ExampleActivity extends Activity { @Override protected void onCreate(@Nullable final ...
By using startActivityForResult(Intent intent, int requestCode) you can start another Activity and then receive a result from that Activity in the onActivityResult(int requestCode, int resultCode, Intent data) method. The result will be returned as an Intent. An intent can contain data via a Bundle ...
This Activity code will provide basic functionality for including a Google Map using a SupportMapFragment. The Google Maps V2 API includes an all-new way to load maps. Activities now have to implement the OnMapReadyCallBack interface, which comes with a onMapReady() method override that is execute...
Sometimes you may want to start a new activity while removing previous activities from the back stack, so the back button doesn't take you back to them. One example of this might be starting an app on the Login activity, taking you through to the Main activity of your application, but on logging out...
Define a menu in res/menu <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/first_...
This is a very common Exception. It causes your application to stop during the start or execution of your app. In the LogCat you see the message: android.content.ActivityNotFoundException : Unable to find explicit activity class; have you declared this activity in your AndroidManifest.xml? In ...
In themes.xml: <style name="MyActivityTheme" parent="Theme.AppCompat"> <!-- Theme attributes here --> </style> In AndroidManifest.xml: <application android:icon="@mipmap/ic_launcher" android:label="@string/app_name" ...
Let there be Activity B that can be opened, and can further start more Activities. But, user should not encounter it when navigating back in task activities. The simplest solution is to set the attribute noHistory to true for that <activity> tag in AndroidManifest.xml: <activity a...
Activity is the root UserInterface in Android and have it's own life-cycle. MainActivity.java public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Toast.makeText(this, "Activ...
Objective-C NSString *textToShare = @"StackOverflow Documentation!! Together, we can do for Documentation what we did for Q&A."; NSURL *documentationURL = [NSURL URLWithString:@"http://stackoverflow.com/tour/documentation"]; NSArray *objectsToShare = @[textToShare, docum...
A basic AppComponent that depends on a single AppModule to provide application-wide singleton objects. @Singleton @Component(modules = AppModule.class) public interface AppComponent { void inject(App app); Context provideContext(); Gson provideGson(); } A module to use to...
1. Passing integer data: SenderActivity Intent myIntent = new Intent(SenderActivity.this, ReceiverActivity.class); myIntent.putExtra("intVariableName", intValue); startActivity(myIntent); ReceiverActivity Intent mIntent = getIntent(); int intValue = mIntent.getIntExtra("intVa...
For one-time, non-constant requests for a user's physical activity, use the Snapshot API: // Remember to initialize your client as described in the Remarks section Awareness.SnapshotApi.getDetectedActivity(client) .setResultCallback(new ResultCallback<DetectedActivityResult>() { ...
Often you will want to wrap some of Android's classes in easier to use utility classes. Those utility classes often require a context to access the android OS or your apps' resources. A common example of this is a wrapper for the SharedPreferences class. In order to access Androids shared preference...
If you want to detect when your user starts or finishes an activity such as walking, running, or any other activity of the DetectedActivityFence class, you can create a fence for the activity that you want to detect, and get notified when your user starts/finishes this activity. By using a Broadcast...
All fragments should have an empty constructor (i.e. a constructor method having no input arguments). Therefore, in order to pass your data to the Fragment being created, you should use the setArguments() method. This methods gets a bundle, which you store your data in, and stores the Bundle in the ...
In /res/values/strings.xml: <string-array name="spinner_options"> <item>Option 1</item> <item>Option 2</item> <item>Option 3</item> </string-array> In layout XML: <Spinner android:id="@+id/spinnerName" ...
Assume an application with a MainActivity which can call the Next Activity using a button click. public class MainActivity extends AppCompatActivity { private final String LOG_TAG = MainActivity.class.getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { ...
It is common for an AsyncTask to require a reference to the Activity that called it. If the AsyncTask is an inner class of the Activity, then you can reference it and any member variables/methods directly. If, however, the AsyncTask is not an inner class of the Activity, you will need to pass an A...

Page 1 of 3