Tag: android-activity

Android – startActivityForResult outside an Activity?

I have a wrapper class (BluetoothDiscoverer) which is instantiated within a Service. This class obtains a BluetoothAdapter and checks whether Bluetooth is enabled before scanning for neighbouring devices. Now if Bluetooth is not enabled I want to be able to do the following within this class (BluetoothDiscoverer): Intent enableBluetoothIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBluetoothIntent, BLUETOOTH_ENABLER); Now […]

Runtime Exception while using the Settings in Android (I am following the udacity Android Developer course)

I am new to android and following the Udacity Android developer course to learn. I am on chapter 3 where they teach about the adding the settings in your app. I have added the SettingActivity from android studio. When I click on settings menu, my app crashes. This is my pref_general.xml file <PreferenceScreen xmlns:android=”http://schemas.android.com/apk/res/android”> <!– […]

How do you pass an object array to an Activity?

I have read posts on passing arrays from and to activities, but I am confused as to how I would do it for my specific case. I have an array of objects called DaysWeather (a DaysWeather[] array) where the objects have several String attributes as well as a bitmap attribute. I read somewhere that you […]

starting a new activity in onCreate works only with delay

I have a simple activity that just shows two buttons, and I would like to load another activity as soon as that one is finished loading. @Override public void onCreate(Bundle savedInstanceState) { dbg(“starting on create”); super.onCreate(savedInstanceState); dbg(“stting content view”); setContentView(R.layout.main); createDrPopup(); } private void createDrPopup(){ dbg( “created new activity”); startActivityForResult(new Intent(this, DrPopup.class), DR_POPUP_ACTIVITY_ID); } I […]

Flag Activity Clear Top destroys target activity and than creating it

I am watching a behavior of Intent.FLAG_ACTIVITY_CLEAR_TOP. For example i have three activities A,B and C Now Flow is A -> B -> C Now when i am starting A from C with this flag with following code. Intent intent_to_a=new Intent(C.this,A.class); intent_to_home.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent_to_a); AFAIK, Intent.FLAG_ACTIVITY_CLEAR_TOP should remove B and should resume the A .It also […]

Funky android activity behavior when screen turns off?

I’m seeing some interesting activity flow when android turns off the screen and locks the screen… my app goes through the regular flow, onCreate, onStart and onResume. Then, I let my phone sit there. When the screen goes black, onPause is called. That’s fine. Then 5 seconds later, the app is killed (onStop, onDestroy). That’s […]

How to finish an activity from another activity

If Activity A is related to task T1 and Activity B is related to task T2, how can I finish Activity A from Activity B? I need this because my application can be started from its shortcut or through notifications.

Set theme color dynamically

I am using themes (dynamically) in my android app, like this: my_layout.xml (extract): <TextView android:id=”@+id/myItem” style=”?my_item_style” /> attrs.xml (extract): <attr name=”my_item_style” format=”reference” /> themes.xml (extract): <style name=”MainTheme.Blue”> <item name=”my_item_style”>@style/my_item_style_blue</item> </style> <style name=”MainTheme.Green”> <item name=”my_item_style”>@style/my_item_style_green<item> </style> styles.xml (extract): <style name=”my_item_style_blue”> <item name=”android:textColor”>@color/my_blue</item> </style> <style name=”my_item_style_green”> <item name=”android:textColor”>@color/my_blue</item> </style> So, as you can see, I am setting […]

Android memory management granularity – Activity or Process?

I am seeing inconsistent documentation and discussion regarding what happens when Android is low on memory and the steps the OS takes to re-claim memory. More specifically, does Android kill at the granularity of activity/fragment, or entire process? For example, if Activity B is launched in front of Activity A (and both activities are part […]

singleTask launchMode in android not working

So, I have 4 activities Activity Activity1, Activity2, Activity3 and Activity4. I start from Activity1 then on some event I start Activity2 then on some event on Activity2 I start Activity3 as a new task as public void onClick(View v) { Intent intent = new Intent(Activity2.this, Activity3.class); intent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK|Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } Here Activity2 launchMode is decalared […]

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