Android app crashing while loading image - android

I am trying to load around 168kb (after optimization in tinypng.com) image as splash screen. Its crashing with below VERBOSE (no errors)-
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
This is how I have implemented splash screen-
Activity:
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
//setContentView(R.layout.activity_splash1);--> Note this is commented
/* New Handler to start the Menu-Activity
* and close this Splash-Screen after some seconds.*/
new Handler().postDelayed(new Runnable(){
#Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(SplashActivity1.this,MainActivity.class);
SplashActivity1.this.startActivity(mainIntent);
SplashActivity1.this.finish();
}
}, SPLASH_DISPLAY_LENGTH);
}
Manifest Entry:
<activity
android:name=".ui.activities.SplashActivity1"
android:screenOrientation="portrait"
android:theme= "#style/AppTheme.NoActionBar.SplashActivity1">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Styles:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorTheme</item>
<item name="colorAccent">#color/colorBlack</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.NoActionBar.SplashActivity1" parent="AppTheme.NoActionBar">
<item name="android:windowBackground">#drawable/splash1</item>
</style>
Drawable:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/bootpage">
</bitmap>
Running on: Android Emulator API 6
Thanks in Advance

There are two problems here .
1 - if you want your activity to be created without a layout (you have commented setContentView()) then you must use Theme.NoDispaly .
in your manifest :
<activity android:name = "MyActivity"
android:label = "#string/app_name"
android:theme = "#android:style/Theme.NoDisplay" >
2 - why you would call an activity without a ui ?
for splash pages the standard way is to to declare all your ccomponents and your drawables in xml like anyother activity.
i think there is no need not to use a layout in splash.

Related

Why the flash screen in many Android apps is not closed when the back button is clicked?

For example, when you open WhatsApp, during the launch of the app, the splash activity is on the screen. If the user changed his mind and preferred to close the app, the app does not close! He must wait till the app launch and the splash activity disappear … This is almost the case in all Google's Android apps that I have used … How to implement this behavior?
because they overried the onBackPressed() method (in splash screen activity)
override fun onBackPressed() {
//super.onBackPressed()
}
and comment the super.onBackPressed()
you can add logical condition there to decide wheatear to go back or not
override fun onBackPressed() {
if(condtion is true)
super.onBackPressed()
else
Log.e("","process pending")
}
if u MainActivity takes 3 sec to load launch SplachScreenActivity.class
and block it for 3 sec using thread or timer once timer expiries call finish() method which will get back to MainActivity where u find MainActivty ready
They're using a trick. The splash screen is actually just a theme on a dummy activity, which lets them render a static background drawable while the application is still being created by the system. This means you can't actually have any logic running, nor can you create any views on a splash screen, it is just a static image.
res/values/themes.xml
I believe android:windowBackground is the only attribute that will be accepted for a splash screen.
<resources>
<style name="AppTheme_Splash" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/splash_screen</item>
</style>
</resources>
res/drawable/splash_screen.xml
In my example, I display two .png images on the splash screen.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#color/splash_screen_background" />
</shape>
</item>
<item>
<bitmap
android:antialias="true"
android:gravity="center"
android:src="#drawable/splash_logo"
android:tileMode="disabled" />
</item>
<item>
<bitmap
android:antialias="true"
android:gravity="bottom|center_horizontal"
android:src="#drawable/splash_logo_title"
android:tileMode="disabled" />
</item>
</layer-list>
AndroidManifest.xml
Apply the theme #style/AppTheme_Splash, and add MAIN and LAUNCHER intent-filters.
<manifest>
<application
android:name=".BaseApplication"
android:icon="#drawable/app_icon"
android:label="#string/launcher_name"
android:theme="#style/AppTheme_Light">
<activity
android:name=".ui.SplashActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme_Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.HomeActivity"
android:label="#string/app_name"
android:launchMode="singleTask" />
</application>
</manifest>
SplashActivity.java
The onCreate method will be executed after the application is fully loaded. No logic is executed until that point, nor would the activity's View be rendered until after the app is loaded.
public class SplashActivity extends AppCompatActivity {
#Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent homeIntent = new Intent(this, HomeActivity.class);
startActivity(homeIntent);
finish();
}
}
I think that's it!

1gravity contacts picker library for android

Has anyone used 1GravityContactsPicker Library for android.
I just found this yesterday and decided to use this in my app due to its good features. I did everything as mentioned in the steps but when i am starting the activity I am getting a Toast message saying
Attribute undefined; "cp_textColorPrimary". Did you apply the correct
theme
i have checked the documentation of library and heres what i did
1) Added dependency to gradle
2) Added activity file to manifest
3) Enabled contacts permission
4) below is the code
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, ContactPickerActivity.class)
.putExtra(ContactPickerActivity.EXTRA_THEME, R.style.ContactPicker_Theme_Dark)
.putExtra(ContactPickerActivity.EXTRA_CONTACT_BADGE_TYPE,
ContactPictureType.ROUND.name())
.putExtra(ContactPickerActivity.EXTRA_CONTACT_DESCRIPTION,
ContactDescription.ADDRESS.name())
.putExtra(ContactPickerActivity.EXTRA_SHOW_CHECK_ALL, true)
.putExtra(ContactPickerActivity.EXTRA_SELECT_CONTACTS_LIMIT, 0)
.putExtra(ContactPickerActivity.EXTRA_ONLY_CONTACTS_WITH_PHONE, false)
.putExtra(ContactPickerActivity.EXTRA_CONTACT_DESCRIPTION_TYPE,
ContactsContract.CommonDataKinds.Email.TYPE_WORK)
.putExtra(ContactPickerActivity.EXTRA_CONTACT_SORT_ORDER,
ContactSortOrder.AUTOMATIC.name());
startActivityForResult(intent, REQUEST_CONTACT);
}
});
can anyone please help me out with this
I have the same issue.
it's because in his Actvity he test the AppThem directly and if your Application themes does not implement Picker style the check is all time false.
// check if all custom attributes are defined
if (! checkTheming()) {
finish();
return;
}
For fix it, i've juste add new themes in styles.xml
<!-- LIGHT Theme -->
<style name="Theme_Light_Base" parent="#style/ContactPicker_Theme_Light">
<!-- ActionBarCompat -->
<item name="colorPrimary">#color/colorPrimary_light</item>
<item name="colorAccent">#color/colorAccent_light</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark_light</item>
<item name="backgroundColor">#color/background_light</item>
<!--<item name="icTheme">#drawable/ic_palette_black_36dp</item>-->
<!--<item name="icPickContact">#drawable/ic_person_add_black_36dp</item>-->
</style>
<style name="Theme_Light_picker" parent="#style/Theme_Light_Base"/>
<!-- DARK Theme -->
<style name="Theme_Dark_Base" parent="#style/ContactPicker_Theme_Dark">
<!-- ActionBarCompat -->
<item name="colorPrimary">#color/colorPrimary_dark</item>
<item name="colorAccent">#color/colorAccent_dark</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark_dark</item>
<item name="backgroundColor">#color/background_dark</item>
<!--<item name="icTheme">#drawable/ic_palette_white_36dp</item>-->
<!--<item name="icPickContact">#drawable/ic_person_add_white_36dp</item>-->
</style>
and after apply directly on the ActivityPicker in AndroidManifest.xml :
<activity
android:name="com.onegravity.contactpicker.core.ContactPickerActivity"
android:enabled="true"
android:exported="false"
android:theme="#style/Theme_Light_picker">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>

Why progress dialogue is not showing title and message on marshmallow?

In my app, I am integrating progress dialogue and I am using below code for creating progress dialogue
public static void showProgressDialogue(final Context context, String title, String mainMessage) {
progressDialog = new ProgressDialog(context);
progressDialog.setTitle(title);
progressDialog.setMessage(mainMessage);
progressDialog.setIndeterminate(false);
progressDialog.show();
}
And I created 2 emulators one for lollipop and other for marsh mallow. It is showing title and message on lollipop emulator but not showing title and message on marsh mallow emulator. Further I have tried on real device as well. On marsh mallow (Motorolla droid turbo) device it is not showing title and message. For sake of giving complete understanding i am attaching images as well
Above images is taken of lollipop emulator
Above image is taken from marsh mallow emulator
I have googled a lot and could not fine suitable answer that solve my query. Even in one place I found that by changing 'textColorPrimary', it will work. But in my case it did not work. And below is my style.xml code
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textColorPrimary">#color/black</item>
<item name="android:textViewStyle">#style/LoyaltyTextView</item>
<item name="editTextStyle">#style/LoyaltyEditText</item>
</style>
Any help?
As requested, I am posting my manifest as well
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".views.activities.SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.LAUNCHER"></category>
</intent-filter>
</activity>
<activity android:name=".views.activities.MainActivity"/>
<activity android:name=".views.activities.LoginActivity"/>
<activity android:name=".views.activities.SignUpActivity"/>
<activity android:name=".views.activities.ViewAsGuest"/>
<activity android:name=".views.activities.BusinessActivity"/>
</application>

Activity does not show title bar in Android Studio

I have create demo application in Android Studio with two Activity. In First Activity Show Title Bar in preview as well as in emulator but on second Activity does not show Title Bar in Emulator but it display in preview. I have used API 22 in Android Studio.
Please help me....thanx in advn
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/BaseTheme">
<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>
<activity
android:name=".DrawingActivity"
android:label="#string/app_name"
android:theme="#style/BaseTheme"
android:screenOrientation="portrait" />
</application>
Theme style file like this....
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="BaseTheme" parent="AppTheme">
<item name="colorPrimary">#color/action_bar_backgound</item>
</style>
I have also try this...
First Activity Work's fine so I have set that in Second Activity as a setContentView(R.layout.activity_main);
MainActivity.java
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void buttonAction(View v) {
Intent intent = new Intent(MainActivity.this, DrawingActivity.class);
startActivity(intent);
}
}
DrawActivity.java
public class DrawingActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
What you are facing is a bug related to the API 22(5.1) SDK.
Kindly refer the following links for the details on the bug in which the Action Bar is not displayed:
https://code.google.com/p/android/issues/detail?id=159793
https://code.google.com/p/android/issues/detail?id=159780
What you can do for now
Either revert back to API 21 if possible or,
Select API 21 in the compile with (render with) option in Android Studio.
Hope this helps.

Open invisible activity on share action (ACTION_SEND)

There are a lot of similar questions on StackOverfow but they don't solve my problem.
The task is to process in Service intents sent with default share mechanism (ACTION_SEND) from different applications.
But as far as ACTION_SEND is an activity action we have to pick up intent in activity and broadcast it to service. And it will be perfect if this activity will be invisible to the user.
I've researched a lot and have tried many solutions already.
First step of making activity invisible belongs to activity style.
I've tried this values.
android:theme="#android:style/Theme.Translucent.NoTitleBar"
android:theme="#android:style/Theme.Translucent"
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen"
Also i"ve tried to create a custom theme.
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
How the activity in AndroidManifest.xml looks like.
<activity
android:name="xxx.xxx.activities.HandleShareIntentActivity"
android:theme="#style/Theme.Transparent"
android:noHistory="true"
android:excludeFromRecents="true"
android:label="#string/title_activity_handle_share_intent">
<intent-filter>
<action android:name="com.google.android.gm.action.AUTO_SEND"/>
<action android:name="android.intent.action.SEND"/>
<action android:name="android.intent.action.SEND_MULTIPLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="com.google.android.voicesearch.SELF_NOTE"/>
<data android:mimeType="*/*"/>
</intent-filter>
</activity>
Activity code. No setContentView(). finish() in onCreate().
public class HandleShareIntentActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startService(new Intent(this, xxxService.class).putExtra(
Constants.ACTION_SHARE_KEY, getIntent()));
finish();
}
}
On Nexus 5, android 4.4.4 I do have black screen blink while handling any share event.
Any solutions?
I've tried this values.
Use Theme.NoDisplay.
I Just did this, and it helped in my case:
<activity
android:name=".SensorBoardActivity"
android:theme="#android:style/Theme.NoDisplay"
android:excludeFromRecents="true"
android:noHistory="true">
I see you already have finish(); but just for others it is important to execute it just before leaving the onCreate().

Categories

Resources