Android Splashscreen - action bar comes for a moment and disappears - android

In the app I am developing,I am implementing a splashscreen This splashscreen comes at the start of the app. When the splashscreen is launched, the action bar is visible for a small moment say half a second and then disappears. I am not sure why this is happening. Could any one please help me in resolving this issue. I have implemented the following code in the manifest file.
<activity
android:name="com.example.trycatch.SplashscreenActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:noHistory = "true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
And below is the activity file snippet
#Override
protected void onResume() {
setContentView(R.layout.splashscreen);
super.onResume();
}
Could anyone please help me. Thanks for your time.
PS: I am using sherlock actionbar library

Use the following code in the activity(that means in your java file) before setContentView()
requestWindowFeature(Window.FEATURE_NO_TITLE);

add this in your android manifest file
<activity
android:name="com.example.abc.SplashScreen"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock.NoActionBar" ></activity>

use following code to disappear Action Bar:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();
setContentView(R.layout.splash);
more info

Related

Hide action bar in Android

I am making a android app with android studio with a login at the first site. The problem is that the action bar should be hidden on the login activity but shown on the main activity after the user logged in. Is there a way to do this? I just found tutorials how I can remove it permanently.
Thanks for helping me!
Try this
Add these lines:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 0);
For example:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 0);
setContentView(R.layout.activity_loguin);
And probably you will need to change your extension class.
I guess you have this:
public class Loguin extends AppCompatActivity
Just change AppCompatActivity. ONLY IF YOU NEED IT
public class Loguin extends Activity
in your Login activity replace android:theme line in androidmanifest like below
<activity
android:name=".Login"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" // <<== this
>
Hide Action bar from Activity
<activity
android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
No need to add android:theme, it will automatically show you full screen.
Add one line to onCreate() method.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 0);
Thanks

Android - How to change launcher theme (device theme) programmatically

Briefly;
I'm working on a 'Device Production Test' project. We are developing system applications to test whether the API provided by the manifacturer is stable or not.
I need to set Android launcher application theme programmatically and check system level warnings and errors during this process.
I see this question in SO but the source code link is broken.
How can I change Android theme programmatically?
Thanks in advance
You can use this code in manifest file If you really want to launch the activity which I write.
<activity
android:name=".LaunchedActivityName"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// set your custom theme here before setting layout
super.setTheme(android.R.style.Theme_Holo_Light_DarkActionBar);
setContentView(R.layout.activity_main);
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}

Close/Kill Android application from recent application on soft key press

I have a overlay view over all apps. I want to close the overlay view from screen on soft key press (home, back and recent). I have a transparent activity with no content which is starting a service having overlay view.
public class SampleOverlayShowActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startService(new Intent(this, SampleOverlayService.class));
}
#Override
protected void onPause() {
SampleOverlayService.stop();
finish();
super.onPause();
}
}
Inside manifest
<activity
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:name="SampleOverlayShowActivity"
android:excludeFromRecents="true"
android:theme="#android:style/Theme.Dialog" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Everything is working fine expect recent apps. Activity still show up on recent application button press. It got removes when I again press recent application button.
This should be much simpler than trying to override soft key behaviour to do clean up. Instead make sure the activity is launched so that it has no recents trace. From the manifest that means adding noHistory and excludeFromRecents
<activity android:excludeFromRecents="true"
android:noHistory="true"
android:name=".."
...>
<intent-filter>
...
</intent-filter>
</activity>
Note that android:excludeFromRecents works for the task only, so you probably want to make sure that activity is a new task too, using the appropriate flags (android:launchMode="singleTask")

How prevent calling oncreate method by system when rotation screen happenes?

Hi stackoverflow friends. I have an player music and I call in oncreate playSong(id)(id is index of an array which has a path music in that index of array.But there is this problem that when rotates Screen then songs over and over plays from first index in array. I guess becuase oncreate method is called after each time event rotation. Also I want my app prevent from rotation becuse may be this event have bad effect in others activity.too,
How I can fix these type of issues?
You can use
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
or
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
to lock the orientation. Because as you mentioned, the onCreate is called everytime the screen rotates.
But you have to call it before the setContentView(R.layout.main)
Could look like this:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(R.layout.main);
}
you can do like this android:configChanges="orientation|keyboardHidden|screenSize"
hope it will help you
add it to manifest as follows as an example
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:configChanges="orientation|screenSize|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
You could add android:configChanges="orientation" to Activity tag on AndroidManifest.xml. Try it.
You could add android:configChanges="orientation|screenSize" to Activity tag on AndroidManifest.xml. It will helpful.

Android App - disappearance of app GUI

I'm trying to create a simple app, whose main task is to open the browser on defined URL.
I've created first Activity:
public class MyActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
Intent myIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://my.url.tld"));
startActivity(myIntent);
}
Here's my AndroidManifest.xml:
<manifest ...>
<application ...>
<activity android:name=".MyActivity" ...>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
This code is fully functional, but before it opens the browser, it displays a black background - blank app GUI. I didn't figured out, how to go directly do the browser (without displaying the GUI).
Anyone knows?
Add this theme declaration to your activity definition in you manifest
<activity android:name=".MyActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar"
>
Be careful with this, you must call finish(); from your activity after you are done with it otherwise users could get stuck with an invisible activity that prevents them from interacting the phonetop.

Categories

Resources