I have created a widget, but I'd like to add an activity to be installed in the phone as well, like a configuration screen, what's the best method to accomplish that with a widget? thanks!
I need an activity that I can access anytime without having to re-create to setup an alarm, which is an extra feature in the widget, does it work for my approach?
In addition to setting up your activity to be a configuration activity for the app widget, you can include other <intent-filter> elements as needed in your manifest for other scenarios, such as the standard MAIN/LAUNCHER <intent-filter> to make the activity appear in home screen launchers.
Just beware that these activities are started in different ways, and so you may wish to use getIntent() and examine how your activity was launched to adjust your behavior accordingly.
Related
To clarify the question:
I have seen multiple Apps in the Playstore that are widget only Apps without visible activities.
I tried to create one myself but I need to define a launcher Activity. Once I use the configuration Activity of the Widget as a launcher the app becomes visible in the app overview in Android.
https://i.imgur.com/lhx0TDG.png
If I dont define a launcher Activity I cant even deploy the app on the emulator.
The developerguide on https://developer.android.com/guide/topics/appwidgets/index.html about Widgets isnt really clear about how to handle this case.
Any help or directions where to find information is appreciated.
If you want to create a widget only android application without any activity. You don't have to declare any intents for your activity. Just pass the intent filter for android.appwidget.action.APPWIDGET_CONFIGURE It will make the activity load when the user adds it to their home screen. Now you can simply declare your configuration class with your widget layout xml file with android:configure attribute liking to the class file the widget runs on.
Hope this helps.
I want to be able to change which Activity is run when the user runs the application.
I know how to do this in the application's manifest file, but I would like to do it programmatically after install. The reason being, I want the user to be able to choose which screen loads when he opens the application.
How can I do this? The only way I know of seems very clunky: have an essentially empty Activity which has the MAIN intent-filter - which then reads the user's settings and transfers the user to the desired Activity. This creates a lot of mess, like the back-stack needs to be considered, and the overheads of loading one activity straight after another seems wasteful of time and resources.
You cannot change launcher activity dynamically.
As you said it is possible by saving user preferences and start desired activity each time. I have tried it and it is fast enough to not show itself. Don't remember to call finish on main activity. it will solve back stack problem.
Also you can use different fragments for different activities and decide which one should be added to main activity. It may be faster. However as I said it is fast enough to start a new activity and hide main activity because it is done in onCreate method. Don't worry about that.
My issue is when an Android Application goes in the background. When I click the Home button and launch my app again from the home screen by clicking the Application icon, it should display the the same screen from which I went to the Home screen. But it calls the onDestory() method then comes out of my application. I thought the application is killed by the system because of memory requirement etc., but I need tokeep the activity and it should again show the same screen where I left instead of starting all over again.
This may be achieved like maintaining sessions.
try putting
android:alwaysRetainTaskState="true"
in the androidmanifest.xml for those activities, i think ICS does that by default now.
The Application will show you the same screen when return after "home" button if your app with different screens is made of different activities to show the interface parts... But if you just make some objects
visible=true or false
so, after resume you'll see the first view... Try to use Intents between different activities... And show a piece of code to help you... Maybe the problem is in overriding of onDestroy, onPause, onResume methods
I'm working on an Android Activity which should not be full screen and thus uses Dialog theme. This can be achieved by adding
android:theme="#android:style/Theme.Dialog"
to the activity definition in Manifest file.
Visually that does what I expect. However, when the user interacts with the device in an area outside of this activity, the app in the background does not receive this input.
Is there a possibility to achieve this?
that is not possible with your solution as there is only one Activity possible to be active. You could try that with Fragments but I doubt that you could open your App and navigate the Homescreen / whatever in the meantime.
I have an NoContentViewActivity which has no Content View (i.e. I did not call setContentView() in the onCreate of my Activity).
My question is how can I keep the content view of the launching activity on the screen? Right now, I am getting a blank screen whenever I launch NoContentViewActivity? I want the content view of the launching activity (the activity which start the NoContentViewActivity) to show on the screen.
Thank you for any help.
Excuse me, people, but my guess is that hap497 wants exactly the thing he wants. There is a bunch of situations where invisible activity would fit while Service will not.
Imaging you want to show a set of dialogs, each next of them is shown after the previous one based on the user choices. And imaging you want to have this (exactly the same) functionality to be available when pressing different buttons on different (lots of them) activities.
To write the same dialog processing logic would be an overkill whether the transparent activity will deal nicely...
Anyway, as stated above, all you need to do is to specify:
android:theme="#android:style/Theme.Translucent"
or
android:theme="#android:style/Theme.Translucent.NoTitleBar"
(if you do not want a titlebar either)
It sounds like you'd be better off using a Service than an Activity. Activities are for code that is to be viewed; Services are for code that runs without a UI, which is what it sounds like you want.
An Activity with no Views assigned is an empty black screen, so it will still obscure the calling Activity. You could make your Activity transparent by assigning it a transparent theme:
android:theme="#style/Theme.Translucent"
Keep in mind though, that your invisible Activity will have focus, so the user won't be able to interact with the Activity underneath.
Why do you want to create a fully transparent Activity? As Daniel suggests, a Service might be a better solution to your problem if you genuinely don't want any user interaction.