Tutorial by Examples: activity

Launch mode defines the behaviour of new or existing activity in the task. There are possible launch modes: standard singleTop singleTask singleInstance It should be defined in android manifest in <activity/> element as android:launchMode attribute. <activity android:launchM...
If you need to send events from fragment to activity, one of the possible solutions is to define callback interface and require that the host activity implement it. Example Send callback to an activity, when fragment's button clicked First of all, define callback interface: public interface Samp...
As your activity begins to stop, the system calls onSaveInstanceState() so your activity can save state information with a collection of key-value pairs. The default implementation of this method automatically saves information about the state of the activity's view hierarchy, such as the text in an...
Like Getting a result from another Activity you need to call the Fragment's method startActivityForResult(Intent intent, int requestCode). note that you should not call getActivity().startActivityForResult() as this will take the result back to the Fragment's parent Activity. Receiving the result c...
If you want to clear your current Activity stack and launch a new Activity (for example, logging out of the app and launching a log in Activity), there appears to be two approaches. 1. Target (API >= 16) Calling finishAffinity() from an Activity 2. Target (11 <= API < 16) Intent intent ...
adb -s <serialNumber> shell dumpsys activity activities Very useful when used together with the watch unix command: watch -n 5 "adb -s <serialNumber> shell dumpsys activity activities | sed -En -e '/Stack #/p' -e '/Running activities/,/Run #0/p'"
public class ReplaceFont { public static void changeDefaultFont(Context context, String oldFont, String assetsFont) { Typeface typeface = Typeface.createFromAsset(context.getAssets(), assetsFont); replaceFont(oldFont, typeface); } private static void replaceFont(String oldFont, Type...
public static final int PLACE_AUTOCOMPLETE_FROM_PLACE_REQUEST_CODE=1; public static final int PLACE_AUTOCOMPLETE_TO_PLACE_REQUEST_CODE=2; fromPlaceEdit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ...
using Android.App; using Android.OS; using Android.Content; using Android.Database; using Xamarin.Forms; namespace contact_picker.Droid { [Activity (Label = "ChooseContactActivity")] public class ChooseContactActivity : Activity { public string type_num...
using System; using Android.App; using Android.Content; using Android.Content.PM; using Android.Runtime; using Android.Views; using Android.Widget; using Android.OS; using Xamarin.Forms; namespace contact_picker.Droid { [Activity (Label = "contact_picker.Droid", Icon = &...
Launch standalone player activity Intent standAlonePlayerIntent = YouTubeStandalonePlayer.createVideoIntent((Activity) context, Config.YOUTUBE_API_KEY, // which you have created in step 3 videoId, // video which is to be played 100, //The time,...
public class CustomYouTubeActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener, YouTubePlayer.PlayerStateChangeListener { private YouTubePlayerView mPlayerView; private YouTubePlayer mYouTubePlayer; private String mVideoId = "B08iLAtS3AQ"; ...
Activity lifecycle is quite more complex. As you know Activity is single page in the Android app where user can perform interaction with it. On the diagram below you can see how Android Activity lifecycle looks like: As you can see there is specific flow of Activity lifecycle. In the mobile appl...
import android.os.Bundle; import android.os.Handler; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.util.Log; import android.widget.T...
public abstract class BaseActivity extends AppCompatActivity { private Map<Integer, PermissionCallback> permissionCallbackMap = new HashMap<>(); @Override protected void onStart() { super.onStart(); ... } @Override public void setConten...
The Problem You have a set of things to do (activities). Each activity has a start time and a end time. You aren't allowed to perform more than one activity at a time. Your task is to find a way to perform the maximum number of activities. For example, suppose you have a selection of classes to ch...
Click to File → New → Kotlin Activity. Choose a type of the Activity. Select name and other parameter for the Activity. Finish. Final class could look like this: import android.support.v7.app.AppCompatActivity import android.os.Bundle class MainActivity : AppCompatActivity() { ...
This is a just a simple example of how to use GooglePlay Service's ActivityRecognitionApi. Although this is a great library, it does not work on devices that do not have Google Play Services installed. Docs for ActivityRecognition API Manifest <!-- This is needed to use Activity Recognition! -...
PathSense activity recognition is another good library for devices which don't have Google Play Services, as they have built their own activity recognition model, but requires developers register at http://developer.pathsense.com to get an API key and Client ID. Manifest <application andro...
Activity is complete screen. UI is XML based and package com.example.android.activity; import android.os.Bundle; import android.app.Activity; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceSta...

Page 2 of 3