Is it possible to create an activity in Android that doesn't take up the entire screen? I would like to create one that is only 1 pixel x 1 pixel wide and launch it.
No it is not. An Activity is designed to be the current active screen.
You can 'fool' people with the view that goes with the Activity, such as making it (partly) transparent but your Activity will still be the one receiving touches.
Create activity with dialog Theme by using this
android:theme="#android:style/Theme.Dialog"
Activities are often presented to the user as full-screen windows,
They can also be used in other ways: as floating windows (via a theme with windowIsFloating set)
or
embedded inside of another activity (using ActivityGroup).
If you want to create with given pixel you can not do it.. Instead you can go for Fragments, DialogInterface in Android which can be created with size specified in layout xmls
Related
I'm working on my small app and I have terrible problem with dialogs. Partially my question will be technical, partially general.
For example I have the following scenario: 1) user select file type 2) user select file 3) user select some additional options - list of about 5/6 options.
I'm wondering if to do this as some kind of three steps wizard (for each step separate dialog) either as one activity with three buttons/elements for selecting the appropriate elements. How do you think? I would like to have my app giving some kind of light appearance to users, thus I would prefer not to have heavy things. have you seen any good examples of more complicated dialogs/activities? Any official guide for more complicated dialogs?
Moreover some technical questions:
1) Is that possible to have activity (full screen) looking as dialog (style)? If yes, how?
2) As for now I use DialogFragment. However android by default sets its dimensions in the way that there is no need to resize them when changing screen orientation (screen smaller dimension is the base for setting dialog size). In consequence when having screen in vertical orientation huge part of screen is not used by dialog. How to change that to have dialog occuping almost the whole screen, but also resizing correctly when changing screen orientation and if possible with still keeping setRetainInstance(true) (less problems with dialogs when changing orientation)?
use the following line of code in your activity below setContentView(R.layout.activity_main);
setTheme(android.R.style.Theme_Dialog);
refer following link,
Android: how to create a transparent dialog-themed activity
Ive been doing some reading, and got a little confused. In Android development, is there a difference between a Screen and an Activity? What are they? I was reading about an Activity having multiple screens.
An activity is a piece of your application which should handle a single specific task (example, receive input from the user or display images or whatever you want).
The part you are referring, "supporting multiple screens" can be explained as a best practice you should follow when developing your application: this is simply the designing of proper layouts based on different possible screen sizes and densities. There is nothing such a "Screen" class in android.
So the relationship between an Activity and the moltitude of screen sizes out there is mapped by the layout XMLs defined in the proper layout folders in your application. The android OS will choose and handle the layout for your activity based on the hardware screen available and the closest-to-best layout you defined.
Think of an activity as a "window" on a desktop OS (like Windows7 or MacOSX or Ubuntu) that allows you to see only one window at a single time. If you have 10 different activities in your app the user may see up to 10 different windows. The android OS will pick the most compatible layout you defined based on the real screen display the user has and places the GUI component accordingly.
An Android activity is the screen you see on your device ie a welcome screen with buttons or whatever. The activity can call other activities which then will show on your device screen. An activity is where you define all your logic for what happens on your device (Of course you can define the layout of your activity in a layout xml file).
An Activity is similar to a form(If you are aware of web development form).
Screen is just displaying activity so there is no object like screen.
For layout control of an Activity you can use main.xml ( Also it can be done using code in your activity extended class.)
When do I need to create a new activity and when do I need to change the view?
My app needs to do:
Screen #1
two big buttons(sort of menu)
Screen #2
list of items - depend on the selection on prev screen
Screen #3
another list - depend on the selection on prev screen
Screen #4
show item
All screens need to have the same menu menu (the last has another button)
Do I need to create an activity for each screen or just change the view in the same activity?
Maybe I need to create a parent class myBase that will extend activity and all my activities will extend him?
A View in Android is a widget that displays something. Buttons, listviews, imageviews, etc. are all subclasses of View. When you say "change view" I assume you mean change the layout by using setContentView(). This usually only needs to be done once per activity. An Activity is basically what you are referring to as a screen. To answer your question, it sounds like you need four separate activities (one for each screen).
You should create separate activities for you screens. Android handles the back button of the device by popping the current activity out from the stack and displaying the last one. So if for example the user wants to return to screen 2 for another selection, the back button does this.
The "right" way to do it is to use Activity for each screen and use the <include> tag for the menu you would like to be in all screens.
This way you will have the "back" button act as it should be and it would be easier for you to handle when switching screens.
To use the , you should put the things you want to reuse into extra files.
Then you can use it as follows:
<!-- my_header.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/text01"/>
In another file include it with:
<include layout="#layout/my_header" />
<!-- your other stuff -->
activity is like canvas where you put your drawing as view.Yes you can set all above four view in single activity but it will depend how you handle it and does your app needs it to be done like this.
View is Display System of Android where you define layout to put subclasses of View in it eg. Buttons, Images etc. But Activity is Screen System of Android where you put display as well as user-interaction,(or whatever which can be contained in full-screen Window.)
Now for your question,you are creating full window screen#2 ,screen#3... ,so it is activity.
In these screen you can define layout/or Views.
I hope it helps.
You should create 4 xml files... and play Around changing content using setContentView(R.Layout.yourxml);..
you can do this using single Activity.. it depends on how big the class becomes.. if its too heavy with lot of different stuff, for the sake of cohision and to avoid coupling use multiple Activities
I've recently started developing Android Apps, and whilst the model is making more sense the more I look at it, I cannot do something (nor find any reference material on it) which to me seems quite simple.
I have an activity which has five buttons along the bottom, and a blank View taking up the rest of the screen. I want, upon clicking these buttons, for an activity to be opened in (and confined to) this view. I can get a new activity running without incident, but this opens in a new screen.
If anyone can show me an easy way to launch a (sub/child?) activity within a view which is defined in the parent activity's layout xml file - equally, it could be created in the parent activity - you'd really be doing me a favor!
I'd recommend taking a look at TabHost. The tabhost is an Activity itself, and the sub-views are all Actvities as well.
Here is a good tutorial that'll get you going very quickly. There is a more work to create (optional) icons for the tabs (also describe in the tutorial).
Hope this helps.
Edit* You mentioned buttons being at the bottom of the screen. Take a look at this SO Question
You can achieve that by using an ActivityGroup... here is a simple example which shows how to do it using a TabActivity:
http://web.archive.org/web/20100816175634/http://blog.henriklarsentoft.com/2010/07/android-tabactivity-nested-activities/
Of course, you will have to change the code since you are not using TabActivities. Just take a look at the getLocalActivityManager and getDecorView methods that is what you will be using.
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.