Switch button perform hide splash screen - android

I'm using Switch button (if switch button on its disable splash else working normal) for Disable splash screen. But I can't doing it. I'm try android-activity-alias but I'm not get any success. Please help me. (Also I'm using Android-Studio 2.3.0). Here is my code for
This is my Switch Button layout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#drawable/bg">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:text="#string/switchButtonSplash"/>
<LinearLayout
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="fill"
android:orientation="horizontal">
<Switch
android:id="#+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#android:color/darker_gray"/>
</LinearLayout>
</ScrollView>
My Switch Button
This is my Switch Button programming
package ahmer.afzal.myproject;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.CompoundButton;
import android.widget.Switch;
public class SettingsActivity extends AppCompatActivity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Switch toggle = (Switch) findViewById(R.id.switch1);
toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
{
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if (isChecked)
{
startActivity(new Intent(SettingsActivity.this, MainActivity.class));
finish();
}
else
{
startActivity(new Intent(SettingsActivity.this, SplashActivity.class));
finish();
}
}
});
setContentView(R.layout.setting_app_bar_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null)
{
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
if (item.getItemId() == android.R.id.home)
{
finish();
}
return super.onOptionsItemSelected(item);
}
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ahmer.afzal.myproject"
android:versionCode="550"
android:versionName="19.00">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<application
android:exported="true"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:screenOrientation="portrait"
android:theme="#style/AppTheme">
<activity
android:name=".SplashActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
</activity>
</application>
</manifest>

You can't take decision on the basis of what the status of switch button when the app last opened because switch button will not retain its state, you have to save it somewhere when user changes it.
In that case what you can do is save the status of your switch button in sharedPreferences and in onCreate() of your launcher activity check that status and take decision accordingly. But in this case also if your launcher activity is Splash then it will be shown at least once for a fraction of a second until you make those checks.
P.S: You can't change the launcher activity which is declared inside your manifest.

First I created new LauncherActivity and removed previously created SettingsActivity
LauncherActivity
package="ahmer.afzal.myproject"
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
public class LauncherActivity extends Activity
{
public static String TRANSPARENT = "transparent";
private SharedPreferences sharedPref;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
sharedPref = getSharedPreferences("myPrefs", Context.MODE_PRIVATE);
if(!sharedPref.getBoolean(TRANSPARENT, false))
{
startActivity(new Intent(LauncherActivity.this, SplashActivity.class));
}
else
{
startActivity(new Intent(LauncherActivity.this, MainActivity.class));
}
finish();
}
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ahmer.afzal.myproject"
android:versionCode="550"
android:versionName="19.00">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<application
android:exported="true"
android:noHistory="true"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:screenOrientation="portrait"
android:theme="#style/AppTheme">
<activity
android:name=".LauncherActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
</activity>
<activity
android:name=".SplashActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
</activity>
</application>
</manifest>

Related

ImageButtons not working - Android Studio

I have this WelcomeActivity where I programmed 4 ImageButtons to launch another activities.
This is my code:
public class WelcomeScreen extends Activity {
ImageButton completeprofile;
ImageButton gotoportfolio;
ImageButton findfriends;
ImageButton readnews;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome_activity);
completeprofile = (ImageButton) findViewById(R.id.completeprofile);
gotoportfolio = (ImageButton) findViewById(R.id.gotoportfolio);
findfriends = (ImageButton) findViewById(R.id.findfriends);
readnews = (ImageButton) findViewById(R.id.readnews);
completeprofile.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(WelcomeScreen.this, LoginMember.class);
startActivity(i);
}
});
gotoportfolio.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(WelcomeScreen.this, MainActivity.class);
startActivity(i);
}
});
findfriends.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(WelcomeScreen.this, MainActivity.class);
startActivity(i);
}
});
readnews.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(WelcomeScreen.this, RegisterMember.class);
startActivity(i);
}
});
}}
Problem is, they actually behave like buttons when I click them, but no activity is launched, this is the layout declaration:
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="70dp"
android:layout_marginLeft="105dp">
<ImageButton
android:layout_width="55dp"
android:layout_height="55dp"
android:id="#+id/completeprofile"
android:src="#drawable/completeprofile"
android:layout_marginLeft="75dp"
android:contentDescription="completeprofile" />
<ImageButton
android:layout_width="55dp"
android:layout_height="55dp"
android:id="#+id/gotoportfolio"
android:src="#drawable/gotoportfolio"
android:layout_marginLeft="65dp" />
<ImageButton
android:layout_width="55dp"
android:layout_height="55dp"
android:id="#+id/findfriends"
android:src="#drawable/findfriends"
android:layout_marginLeft="65dp" />
<ImageButton
android:layout_width="55dp"
android:layout_height="55dp"
android:id="#+id/readnews"
android:src="#drawable/readnews"
android:layout_marginLeft="65dp" />
</LinearLayout>
Why is this happening? Maybe the intent launch has some issue?
Any ideas?
thanks in advance!
EDIT
Here's the manifest:
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="21"
tools:overrideLibrary="android.support.multidex" />
<supports-screens
android:largeScreens="true"
android:normalScreens="false"
android:requiresSmallestWidthDp="600"
android:smallScreens="false"
android:xlargeScreens="true" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
<!-- <uses-sdk /> -->
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#drawable/logo"
android:label="Shairlook"
android:theme="#style/AppTheme" >
<activity
android:name="com.kkoci.shairlook.SplashScreen"
android:configChanges="orientation"
android:label="Shairlook"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.kkoci.shairlook.MemberActivity"
android:configChanges="orientation"
android:label="#string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.kkoci.shairlook.RegisterMember"
android:configChanges="orientation"
android:label="#string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.kkoci.shairlook.LoginMember"
android:configChanges="orientation"
android:label="#string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.kkoci.shairlook.WelcomeScreen"
android:configChanges="orientation"
android:label="#string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.kkoci.shairlook.YoutubeVid"
android:configChanges="orientation"
android:label="#string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.kkoci.shairlook.ProfileMember"
android:configChanges="orientation"
android:label="#string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.kkoci.shairlook.PortfolioMember"
android:configChanges="orientation"
android:label="#string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.kkoci.shairlook.ForgotPassActivity"
android:configChanges="orientation"
android:label="#string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.kkoci.shairlook.MainActivity"
android:configChanges="orientation"
android:label="Shairlook"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.kkoci.shairlook.WebActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo" >
</activity>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
</application>
#override won't cause problem. It's quite weird if activities are added in manifest and present in same pkg.
can you please add debug Log in onClick(), this will narrow down the problem whether problem is really with callback or not.
try android:clickable="true"/android:focusable="true"/ android:focusableInTouchMode="true" as additional attributes for ImageButton
Hope this helps!
You should remove the '#Override' from above each onClick method, they are not needed and this may be causing you an issue.

Android Splash screen cannot load another activity

The following is the code for my Android splash screen activity.
When it attempts to load another activity, the application crashes on Android 4.0 and 4.1.
I have no idea what's causing this because when it crashes, it does not log any error.
Has anyone come across anything like this befere?
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import org.bitbucket.infovillafoundation.denko.R;
import org.bitbucket.infovillafoundation.denko.component.DaggerDenkoStationComponent;
import org.bitbucket.infovillafoundation.denko.component.DenkoStationComponent;
import org.bitbucket.infovillafoundation.denko.models.DenkoModel;
import org.bitbucket.infovillafoundation.denko.module.DenkoStationModule;
import org.bitbucket.infovillafoundation.denko.service.DenkoStationService;
import butterknife.ButterKnife;
import butterknife.InjectView;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;
public class SplashScreenActivity extends Activity {
#InjectView(R.id.imgLogo)
ImageView logoImage;
#InjectView(R.id.welcomeText)
TextView welcomeText;
private Handler splashHandler = new Handler();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Runnable r = new Runnable() {
#Override
public void run() {
//********************* application is crashing here
Intent mainIntent = new Intent(SplashScreenActivity.this, LanguageOptionActivity.class);
startActivity(mainIntent);
finish();
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}
};
setContentView(R.layout.activity_splash);
ButterKnife.inject(this);
DenkoStationComponent component = DaggerDenkoStationComponent.builder().denkoStationModule(new DenkoStationModule()).build();
final DenkoStationService denkoStationService = component.provideDenkoStationService();
Callback<DenkoModel> callback = new Callback<DenkoModel>() {
#Override
public void success(DenkoModel denkoModel, Response response) {
toast(R.string.server_connection_successful);
denkoStationService.updateDatabaseWithDenkoModel(denkoModel);
}
#Override
public void failure(RetrofitError error) {
toast(R.string.server_connection_failed);
}
public void toast(int textId) {
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_layout,
(ViewGroup) findViewById(R.id.toast_layout_root));
TextView text = (TextView) layout.findViewById(R.id.toast_text);
text.setText(getResources().getString(textId));
Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
};
denkoStationService.fetchDenkoModel(denkoStationService.fetchDenkoLastDataState(), callback);
if (isNetworkAvailable())
splashHandler.postDelayed(r, 3000);
else {
toast(R.string.no_internet_connection);
splashHandler.postDelayed(r, 3000);
}
//********************* application is crashing here
Intent mainIntent = new Intent(this, LanguageOptionActivity.class);
startActivity(mainIntent);
}
#Override
protected void onResume() {
super.onResume();
}
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null;
}
private void toast(int textId) {
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_layout,
(ViewGroup) findViewById(R.id.toast_layout_root));
TextView text = (TextView) layout.findViewById(R.id.toast_text);
text.setText(getResources().getString(textId));
Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
}
Edit: AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.bitbucket.infovillafoundation.denko">
<uses-sdk android:minSdkVersion="14" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="org.bitbucket.infovillafoundation.denko.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="org.bitbucket.infovillafoundation.denko.MAPS_RECEIVE" />
<application
android:name=".application.DenkoApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name=".activity.SplashScreenActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.MainActivity"
android:label="#string/title_activity_home"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar" />
<activity
android:name=".activity.LanguageOptionActivity"
android:label="#string/title_activity_language_option"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAubZsgoC4Z64qcOSpfK4grjrK5zrTEWxk" />
</application>
</manifest>
I think that since the crashes do not occur with a higher Android version, the problem might be resulting from an incompatible OpenGL version.
You can use following Activity with some simple content. Inject the layout (see below) and register in the layout file an onclick-listener (method "forward"). In this method you can call your next activity:
public class SplashScreen extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splashscreen);
}
public void forward(View v){
startActivity(new Intent(this, MainActivity.class), 0);
}
}
splashscreen.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ImageView
android:id="#+id/splashscreen"
android:onClick="forward"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/ic_launcher" />
</LinearLayout>
Add in your AndroidManifest.xml:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" >
<activity
android:name=".SplashScreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" />
</application>
The class "MainActivity" represents your main activity and the class "SplashScreen" represents a simple splash screen.
I hope this will help you:)
The problem i see is that while calling the activity tag you still use .activity in the name attribute
i.e you used android:name=".activity.MainActivity"
instead of android:name=".MainActivity" both for splash screen activity and main activity.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.bitbucket.infovillafoundation.denko">
<uses-sdk android:minSdkVersion="14" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="org.bitbucket.infovillafoundation.denko.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="org.bitbucket.infovillafoundation.denko.MAPS_RECEIVE" />
<application
android:name=".application.DenkoApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name=".SplashScreenActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/title_activity_home"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar" />
<activity
android:name=".activity.LanguageOptionActivity"
android:label="#string/title_activity_language_option"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAubZsgoC4Z64qcOSpfK4grjrK5zrTEWxk" />
</application>
</manifest>
I think you cannot added your splash screen in AndroidManifest.xml.plz check
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splash extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread logoTimer = new Thread() {
public void run() {
try {
int logoTimer = 0;
while (logoTimer < 500) {
sleep(100);
logoTimer = logoTimer + 100;
}
Intent newIntent = new Intent(Splash.this, MainActivity.class);
startActivity(newIntent);
} catch(InterruptedException e) {
e.printStackTrace();
} finally {
finish();
}
}
};
logoTimer.start();
}
}
in Android Manifest.xml
<activity
android:name=".Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Android layout title bar is not visible

I have created xml layout file. And when I give it as content to my Activity the TITLE BAR IS NOT VISIBLE. How can I make it visible. I tried to use setTitle("Title");
protected void onCreate(Bundle savedInstanceState) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
Bundle b = getIntent().getExtras();
int layoutId = b.getInt("layout");
Log.d("====>>>", " " + layoutId);
setContentView(layoutId);
setTitle("Title");
}
function in onCreate() method. I is not work. This is my xml file.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.universityapp.enrollee.FacultyInformationActivity"
android:scrollbars="vertical"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/text_faculty_information_agro"
android:textSize="15dp"
android:textAlignment="center"
/>
</RelativeLayout>
</ScrollView>
I start activity via ListView:
profListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (position){
case 0:
facultyInfoIntent = new Intent(getBaseContext(), FacultyInformationActivity.class);
Bundle b = new Bundle();
b.putInt("layout", facultyLayoutNames[position]);
facultyInfoIntent.putExtras(b);
startActivity(facultyInfoIntent);
}
Log.d("Selected faculty", facultiNames[position]);
}
});
This is my Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.universityapp.universityapp" >
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity android:name="com.universityapp.common.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.universityapp.common.MenuActivity"
android:label="Главное меню" >
</activity>
<activity
android:name="com.universityapp.enrollee.ContacsActivity"
android:label="Наши контакты" >
</activity>
<activity
android:name="com.universityapp.enrollee.Map"
android:label="#string/title_activity_map" >
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="#string/google_maps_key" />
<activity
android:name="com.universityapp.enrollee.MapsActivity"
android:label="#string/title_activity_maps" >
</activity>
<activity
android:name="com.universityapp.bachelor.PlatonusActivity"
android:label="#string/title_activity_platonus" >
</activity>
<activity
android:name="com.universityapp.database.DatabaseActivity"
android:label="#string/title_activity_database" >
</activity>
<activity
android:name="com.universityapp.enrollee.EnrUniversityInfo"
android:label="#string/title_activity_enr_university_info" >
</activity>
<activity
android:name="com.universityapp.enrollee.ProfessionsActivity"
android:label="#string/title_activity_professions" >
</activity>
<activity
android:name="com.universityapp.enrollee.FacultyInformationActivity"
android:label="#string/title_activity_faculty_information" >
</activity>
</application>
</manifest>
Change:
public class MainActivity extends Activity{
}
in your class file to:
public class MainActivity extends AppCompatActivity{
}
I found the answer! I have changed Activity to ActionBarActivity and it works!
To show the title bar you can use this in your onCreate:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
You can do it by doing this (as suggested by HafizWaleedHussain):
public void showTitle() {
try {
((View) findViewById(android.R.id.title).getParent())
.setVisibility(View.VISIBLE);
} catch (Exception e) {
}
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
If this didn't work then open your Android Manifest file and remove this line if it exist:
android:theme="#android:style/Theme.NoTitleBar"
Got o styles.xml and make a new style
<style name="CustomWindowTitleBackground">
<item name="android:background">#323331</item>
<item name="android:windowNoTitle">false</item>
</style>
and call it from Manifest (You can also add other features inside item tags)
<activity
android:name=".st.activity.MyGoogleMap"
android:theme="#style/CustomWindowTitleBackground">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I removed the statement android:theme="#style/AppTheme" in the application tag and the bar started appearing
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
**android:theme="#style/AppTheme"**>

Airpush Application information not avaliable

I have integrated Airpush Bundle SDK in my new android app following this documentation. The problem is I am not seeing any ad. I have provided the MainActivity.java, AndroidManifest.xml & LogCat below. What is the meaning of the message:
Application information not avaliable
and what do I need to do in order to fix this problem?
MainActivity.java
package mg.mynewandroidapp;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import com.oadx.khsz210697.AdListener;
import com.oadx.khsz210697.AdListener.AdType;
import com.oadx.khsz210697.MA;
public class MainActivity extends Activity {
private ListView listView1;
private MA ma;
private AdListener adCallbackListener;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(ma==null)
ma=new MA(this, adCallbackListener, true);
ma.callSmartWallAd();
ma.call360Ad(this, 0, false, null);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public void onBackPressed() {
//Displaying Cached SmartWall Ad
try {
ma.showCachedAd(this, AdType.smartwall);
} catch (Exception e)
{
super.onBackPressed();
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mg.mynewandroidapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/ILYSTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
<meta-data android:name="com.oadx.XXXXXXXXXX.APPID" android:value="MY_APP_ID" />
<meta-data android:name="com.oadx.XXXXXXXXXX.APIKEY" android:value="android*MY_API_KEY"/>
<activity android:exported="false" android:name="com.oadx.XXXXXXXXXX.AdActivity"
android:configChanges="orientation|screenSize"
android:theme="#android:style/Theme.Translucent" />
<activity android:name="com.oadx.XXXXXXXXXX.BrowserActivity"
android:configChanges="orientation|screenSize" />
<activity android:name="com.oadx.XXXXXXXXXX.VActivity"
android:configChanges="orientation|screenSize" android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
</activity>
<service android:name="com.oadx.XXXXXXXXXX.LService" android:exported="false"></service>
<receiver android:name="com.oadx.XXXXXXXXXX.BootReceiver" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
LogCat
11-21 21:06:50.229: I/BunSDK(11425): Status code: 200
11-21 21:06:50.229: I/BunSDK(11425): 360 Json: {"status":204,"message":"ADS Not Available"}
11-21 21:06:50.829: I/BunSDK(11425): Status code: 200
11-21 21:06:50.829: I/BunSDK(11425): SmartWall JSON: {"status":100,"count":0,"url":"","message":"Application information not avaliable"}

android SupportMapFragment Error inflating fragment class

Happy New Year All,
New with implementing Fragments in Android (and I have seen similar posts but I have not been able to get an answer for my problem), so here goes:
I wish to use SupportMapFragment (referenced from the support library v4) and I have created a class that extends FragmentActivity, called TripSummary.java:
package com.project.locationapp;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import android.os.Bundle;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class TripSummary extends android.support.v4.app.FragmentActivity {
private GoogleMap mMap;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, LocationService.class);
stopService(intent);
setContentView(R.layout.activity_trip_summary);
createMap();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_trip_summary, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
//Content?
return super.onOptionsItemSelected(item);
}
private void createMap(){
//if a map has not already been instantiated it'll return null
if(mMap == null){
//instantiate map
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
//check it has been instantiated
if(mMap != null){
Toast.makeText(this, "map done", Toast.LENGTH_SHORT)
.show();
//Manipulate map here (add coordinates/polylines from trip etc etc.)
}
}
}
}
Which gets a layout from activity_trip_summary.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/tripSummary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/trip_summary"
tools:context=".Start" />
<TextView
android:id="#+id/tripDetails"
android:layout_below="#id/tripSummary"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/awaiting_location"
tools:context=".Start" />
<Fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:layout_below="#id/tripDetails"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
AndroidManifest.xml is as follows:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.project.locationapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<permission
android:name="com.project.locationapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.project.locationapp..permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.project.locationapp.Start"
android:label="#string/title_activity_start" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.project.locationapp.LocationService" />
<activity
android:name="com.project.locationapp.TripSummary"
android:label="#string/title_activity_trip_summary" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.project.locationapp.Start" />
</activity>
<activity
android:name="com.project.locationapp.ViewTrips"
android:label="#string/title_activity_view_trips" >
</activity>
<activity
android:name="com.project.locationapp.TripDetail"
android:label="#string/title_activity_trip_detail" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="<-- My Key -->"/>
</application>
</manifest>
The problem I am having in that each time I try to load the activity TripSummary, I get a 'Sorry! stopped unexpectedly' dialog and the app crashes.
LogCat:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.project.locationapp/com.project.locationapp.TripSummary}: android.view.InflateException: Binary XML file line #24: Error inflating class Fragment
I am referencing the google-play-services_lib library (which is also in my workspace) and I also have a copy of android-support-v4.jar in /libs directory within my project.
If you know an answer to my problem, please share!
Thanks in advance.
Please replace:
<Fragment
with:
<fragment
Also, you can get rid of the redundant/incorrect namespace declarations in that element.
Also also, in the future, post the complete stack trace, not just part of one line, to make it easier for people to help you.

Categories

Resources