Launching a transparent activity on HomeScreen - java

So there is an activity containing a webview. On launch/click on App Icon it should launch activity with webview as dialog on the HomeScreen of the device.
Is there a way to achieve this?

Yes, you can do it. Set the theme of MainActivity to Dialog, then you'll achieve it.
<activity android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.Dialog">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
It works fine for me. Hope it can help you~

Related

Figuring out the launcher on this Android Studio Github project

Still a little bit new to Android studio and app development. On this project: https://github.com/watabou/pixel-dungeon, which file is acting as the MainActivity.java file? As in, which file is the main launcher of the application, how do you tell?
The activity with the intent filters android.intent.action.MAIN and android.intent.category.LAUNCHER is the launcher for any app,
Just check which activity it has bellow intent filter that is launcher,
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
In that project PixelDungeon is the launcher activity.
Your launcher activity is defined in your android manifest (AndroidManifest.xml), it should look like this:
<activity
android:name=".activity.Login_screen"
android:label="Activity Validation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
For your case, if you want to edit your launcher activity just change ".activity.Login_screen" for the activity you want to display on launch. However, make sure that there are no duplicate definitions.
As you can see in your code:
<activity
android:label="#string/app_name"
android:name=".PixelDungeon"
android:screenOrientation="portrait">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Trying to have main menu and submenu classes

So my original problem was that in my manifest my menu wasent loading ie
<activity
android:name=".MainMenu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.th3ramr0d.learnar670_1.MAINMENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
This was fixed by loading it at startup ie
<activity
android:name=".MainMenu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
So now my main menu works. However, the buttons inside MainMenu.xml will take you to another .xml file with more buttons. So now I have the same problem. I created another class called SubMenuChapter3 and put it in the manifest as such.
<activity
android:name=".SubMenuChapter3"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.th3ramr0d.learnar670_1.SUBMENUCHAPTER3" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Now this doesnt work I am assuming for the same reason as before with mainmenu. Doesnt crash or give me errors. It just wont open the submenuchapter3 class. I forced the submenuchapter3 class to open by putting
startActivity(new Intent("com.th3ramr0d.learnar670_1.SUBMENUCHAPTER3"));
directly into the MainMenu class outside of an onclick just to see if it was working. When I do that it opens the chapter_3.xml like it is supposed to and the button works. Thanks for the help.
You misunderstood <intent-filter> tag and the way you start activities.
Also maintain proper terminology - Menu and Activity are completely different things.
Everything you need to know about Activities can be found here: Activities | Android Developers
Example:
This entry in AndroidManifest.xml says "show the MainMenu Activity as icon in the launcher":
<activity
android:name=".MainMenu"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
EDIT: This allows Android to start MainActivity. It will also show in the installed app list.
The following Activity will not be displayed in launcher but can be opened from the app:
<activity android:name=".SubMenuChapter3"/>
EDIT: This allows Android to start SubMenuChapter3. It won't show in the installed app list.
These lines say "open the SubMenuChapter3 Activity":
Intent i = new Intent(this, SubMenuChapter3.class);
startActivity(i);
EDIT: You call this code from inside the onClick method inside MainMenu. It will launch SubMenuChapter3.

Installing Android app in a device

I'm a newbie programming for android, I made a simple game some days ago and I tried to install it in a tablet(Android 4.0).
The program works ok, but I got four(4) icons of my app after installation and only one of them is correct(third).
I just want to know how I can to solve this bug so that when I install it in another device it runs ok and get only one icon.
Thanks in advance.
It's because in your manifest you need to change all of your activities EXCEPT your first activity (usually your mainActivity) from:
<activity
android:name=".SecondActivity"
android:label="activity name" >
<intent-filter
android:label="Your App Name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
to:
<activity
android:name=".SecondActivity"
android:label="activity name" >
</activity>
Basically just take the intent-filter out of all your activities that are NOT your main activity. Your main activity needs it so that there is a launcher icon. Hope that helps.
I got four(4) icons of my app after installation
means you have declared more then one Activity in AndroidManifest.xml as launch Activity. to show only one Activity as launcher you will need to declare only one Activity with android.intent.action.MAIN and android.intent.category.LAUNCHER intent-filter.
Declare Main Activity which u want to show in Launcher as:
<activity android:name="MainActvity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and other 3 Activity declare as in AndroidManifest.xml as :
<activity android:name="Actvity_Two"
android:label="#string/app_name" />
<activity android:name="Actvity_Three"
android:label="#string/app_name" />
//declare other in same way ..

Make home intent take to specific application activity?

I've built a project that contains different packages and activities, say:
com.example.package1.Activity1
com.example.package2.Activity2
The first package holds a launcher. On my project manifest file this activity is listening to the home intent:
// Launcher
<activity android:name=".package1.Activity1" android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
// package2.activity1
<activity android:name=".package2.activity1" android:label="#string/package2_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
My problem is that when a user clicks Home the launcher isn't opened, instead the user is taken to the last opened activity of the app. EG: User opens package2.MainActivity from default launcher > goes to another app > clicks home > package2.MainActivity is opened again.
Is this normal? How do I make sure the device Home button takes to .package1.activity1?
If you are trying to create a HOME-screen replacement, then the activity for that needs to have the following in its <activity> tag in the manifest:
android:launchMode="singleInstance"
This will ensure that only one instance of this activity ever exists and that when this activity launches other activities that they will all go into new tasks and not be a part of the HOME-screen replacement's task.
I am not sure but please try to this code:
// package2.activity1
<activity android:name=".package2.activity1" android:label="#string/package2_name" >
<intent-filter>
<action android:name="android.intent.action.View" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

How do I make an applcation's launch icon run the preferences activity?

I would like an app's launch icon run the app's preferences activity (as it has no Activities, only a Service).
The preferences are defined in res/xml/preferences.xml.
Please help me regarding this.
you need to create an activity for your preference (PreferenceActivity), add that activity in your manifest and provide appropriate intent-filters as shown below to run through launcher:
<activity android:name=".MyPreferenceActivity" android:label="Preferences" android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Categories

Resources