Tag: android-activity

Android Service interacting with multiple activities

I’m trying to refactor/redesign an Android app. Currently, I’ve one UI activity (Activity 1) that creates a DataThread. This thread is responsible for network I/O and interacts (provides data) with the UI activity via a handler. Now, I want to add another activity (a new UI screen with Video) – Activity 2. Activity 1 is […]

Database Access in Android

I am creating an android app that is basically a listing of information on Mushrooms. I get this information from an sqlite database. I have a global singleton with a services class inside it in which I use to access my db. Almost every activity accesses the db. Is it better to leave my db […]

Menu Ordering differences due to Fragment and Activity hierarchy. (onCreateOptionsMenu)

Background Developing for Android 3.0, I have a HostActivity that is the superclass of NotebooksActivity and NoteActivity. NotebooksActivity includes a fragment, NotebooksFragment. In HostActivity, I include a menu that I want to appear at the rightmost end of the options menu in the ActionBar, i.e. all menu items in subclasses of HostActivity should appear to […]

How to share common layout between activities without fragment

Is there any possible way to share layout(part) between activities? For example, in my app, all activities have similar layout, the top part is long operation indicator (a progress bar, hidden when no operation is being executed), the bottom part is for showing errors. Only the middle part is different for all activities. See the […]

Does Android restore Intent extras when resuming Activity?

In the Android Activity lifecycle, when Activity.onCreate() is called after resuming (IE. not when activity created initially or in response to screen rotation) would this code return a valid (non-null) Bundle? public void onCreate(Bundle savedInstanceState) { Bundle b = this.getIntent().getExtras(); // is b == null? (when activity is resumed) } I am trying to reproduce […]

Up to parent activity – on Android

After receiving a notification in my app, clicking on it opens activity B. Activity B has a parent activity A. Here is the manifest: <activity android:name=”com.evapp.activities.B” android:label=”@string/title_activity_B” android:parentActivityName=”com.evapp.activities.A” android:screenOrientation=”portrait” > <!– Parent activity meta-data to support 4.0 and lower –> <meta-data android:name=”android.support.PARENT_ACTIVITY” android:value=”com.evapp.activities.A” /> </activity> In activity B I have the up functionality enabled (left […]

Android: How to make launcher always open the main activity instead of child activity? (or otherwise)

I have activities A and B. The A is the one with LAUNCHER intent-filter (i.e. the activity that is started when we click the app icon on home screen). A launches B using startActivity(new Intent(A.this, B.class)). When the user has the B activity open, and then put my application into the background, and later my […]

getActivity().findViewById returns null, called from fragment onActivityCreated

I am following the contacts provider lesson on retrieving contacts and displaying them using fragments. For reference, I have set the API level to 16 (Android 4.1). I have mostly followed this tutorial to the letter, with a few notable exceptions. For example, I import from mypackage.R rather than android.R. My problem is in my […]

How to lock fragment orientation without locking activity orientation?

I have a specific use case where I want a fragment to be locked in portrait mode, but still rotate the activity (and/or other fragments visible in the same activity). Is it possible to do that? All the solutions to locking a fragment orientation suggest to use setRequestedOrientation and lock the activity orientation, but I […]

Send Data from Service To Activity Android

I am building a music player that uses a service for playback. I have an Activity UI that controls (play, pause, next, …) the service. I want to update the UI from my service when the next or previous button is pressed. I thought of passing an integer value. Here is my code: I have […]

Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.