Activity wont start with "startActivity();" - java

Here's my code for DroidArmoryActivity
package com.maxgenero.droidarmory;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
public class DroidArmoryActivity extends Activity implements View.OnClickListener {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()) {
case R.id.ibM4A1:
Intent intentM4A1 = new Intent("com.maxgenero.droidarmory.M4A1GUN");
startActivity(intentM4A1);
break;
}
}
}
It's not starting the java file (Activity) at all, no errors. Btw, the case is looking for an imageButton.
Here's my Manifest, at least the part you need:
<activity android:name=".M4a1"
android:label="#string/app_name"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="com.maxgenero.droidarmory.M4A1" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
And the file name for the java file is M4a1.java. If you need more info let me know, thanks.

I dont see where you define a listener on your Button or your View that will be clicked to launch the second Activity ??
yourView.setOnClickListener(this);
the second thing is that you should add declare your activity on your manifest file on the tag like this :
<activity android:name="your.package.name.NameOfYourAcitivity" />
the last thing is : try to instantiate the intent like this :
this.startActivity(new Intent(this, SecondActivity.class));
Regards,

Instead of...
case R.id.ibM4A1:
Intent intentM4A1 = new Intent("com.maxgenero.droidarmory.M4A1GUN");
startActivity(intentM4A1);
Try
Intent intentM4A1 = new Intent(this, ACTIVITY_NAME.class);
startActivity(intentM4A1);
Also dont forget to call your setOnclickListener().

Related

Why is my accessibility service not being started?

I have created an accessibility service to see if I can perform gesture navigation with my app. The problem is my accessibility service is not being started at all. A possible hint into this problem is that I do not see my app in the accessibility portion of the settings page. I have added the proper permission in my Manifest file, and do not see where I am going wrong.
Here is my Manifest file:
<service
android:name=".AccessibilityService"
android:enabled="true"
android:exported="true"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
android:label="#string/accessibility_service_label">
<meta-data
android:name="android.accessibilityservice"
android:resource="#xml/accessibility_service_config" />
</service>
Here is my accessibility service configuration XML file:
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFeedbackType="feedbackAllMask"
android:accessibilityFlags="flagDefault"
android:canRequestEnhancedWebAccessibility="true"
android:canRetrieveWindowContent="true"
android:packageNames="com.example.adtry3"
android:canRequestTouchExplorationMode="true"
android:settingsActivity="com.example.adtry3.MainActivity" />
Here is my accessibility service class:
package com.example.adtry3;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.annotation.TargetApi;
import android.os.Build;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import androidx.annotation.RequiresApi;
import java.util.List;
#TargetApi(Build.VERSION_CODES.DONUT)
public class AccessibilityService extends android.accessibilityservice.AccessibilityService {
#Override
public void onServiceConnected(){
System.out.println("ONSERVICECONNECTED");
AccessibilityServiceInfo info = getServiceInfo();
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_ALL_MASK;
info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
info.packageNames = new String[] {"com.example.adtry3"};
info.notificationTimeout = 100;
setServiceInfo(info);
}
#RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
#Override
public void onAccessibilityEvent(AccessibilityEvent event) {
System.out.println("Testing");
}
#Override
public void onInterrupt() {
}
public void onUnbind(){ //service is being terminated, do final one-time operations here
}
}
Lastly, this is the OnCreate method of my MainActivity.java:
#Override
protected void onCreate(Bundle savedInstanceState) {
Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
startActivityForResult(intent, 0);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
If I am missing something, or if you know what is going on, please let me know. I have search on other StackOverflow answers and have had no luck. Thank you.
add this filter to your <service declaration in manifest
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
also you may have to add these lines in your service config xml
android:description="#string/accessibility_service_desc"
android:notificationTimeout="25"

Why is my program crashing when button is clicked?

I am trying to make a login and register app where the register details are stored on a database within android studio. Can you please help me as when i run my program the next page does not appear (shown code for one page that won't appear from main menu which is the register activity). If you also know how to make a sql database for a login and register in android studio would be much appreciated. Thanks
Main Activity:
package com.example.emily.loginapp;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button Login, Register, Delete, Update;
int status = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Login = (Button) findViewById(R.id.Login);
Register = (Button) findViewById(R.id.Register);
Delete = (Button) findViewById(R.id.Delete);
Update = (Button) findViewById(R.id.Update);
Login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
status = 1;
Bundle b = new Bundle();
b.putInt("status", status);
Intent i = new Intent("login_filter");
i.putExtras(b);
startActivity(i);
}
});
Register.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent("register_filter");
startActivity(i);
}
});
Update.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
status = 2;
Bundle b = new Bundle();
b.putInt("status", status);
Intent i = new Intent("login_filter");
i.putExtras(b);
startActivity(i);
}
});
Delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
status= 3;
Bundle b = new Bundle();
b.putInt("status", status);
Intent i = new Intent("login_filter");
i.putExtras(b);
startActivity(i);
}
});
}
}
Register:
package com.example.emily.loginapp;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.Button;
import android.widget.Toast;
public class RegisterActivity extends AppCompatActivity {
EditText USER_NAME, USER_PASS, CON_PASS;
String user_name, user_pass,con_pass;
Button REG;
Context ctx = this;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_register);
USER_NAME = (EditText) findViewById(R.id.reg_user);
USER_PASS = (EditText)findViewById(R.id.reg_pass);
CON_PASS = (EditText) findViewById(R.id.con_pass);
REG = (Button) findViewById(R.id.user_reg);
REG.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
user_name = USER_NAME.getText().toString();
user_pass = USER_PASS.getText().toString();
con_pass = CON_PASS.getText().toString();
if (!(user_pass.equals(con_pass))){
Toast.makeText(getBaseContext(),"Passwords are not matching", Toast.LENGTH_LONG).show();;
USER_NAME.setText("");
USER_PASS.setText("");
CON_PASS.setText("");
}else{
DatabaseOperations DB = new DatabaseOperations(ctx);
DB.putInformation(DB, user_name, user_pass);
Toast.makeText(getBaseContext(),"Registration success", Toast.LENGTH_LONG).show();
finish();
}
}
});
}
}
LOGCAT:
03-09 22:33:25.504 2672-2672/com.example.emily.loginapp D/AndroidRuntime: Shutting down VM
03-09 22:33:25.537 2672-2672/com.example.emily.loginapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.emily.loginapp, PID: 2672
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=register_filter }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1798)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1512)
at android.app.Activity.startActivityForResult(Activity.java:3917)
at android.app.Activity.startActivityForResult(Activity.java:3877)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:784)
at android.app.Activity.startActivity(Activity.java:4200)
at android.app.Activity.startActivity(Activity.java:4168)
at com.example.emily.loginapp.MainActivity$2.onClick(MainActivity.java:43)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
03-09 22:33:36.952 2672-2679/com.example.emily.loginapp W/art: Suspending all threads took: 29.841ms
manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.emily.loginapp">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
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=".DeleteActivity"
android:label="#string/title_activity_delete"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".LoginActivity"
android:label="#string/title_activity_login"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".RegisterActivity"
android:label="#string/title_activity_register"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".UpdateActivity"
android:label="#string/title_activity_update"
android:theme="#style/AppTheme.NoActionBar"></activity>
</application>
</manifest>
You are using using an intent flag(register_filter) which is not available on the device thats why it is crashing the application...!
The constructor of the Intent class should be call with the context of
the activity/app and the activity on which you have to move(If you are
not using an activity which is not available on the device)...!
You should use the below code to access the RegisterActivity,
Intent i = new Intent(MainActivity.this, RegistrationActivity.class);
startActivity(i);
You need to create your intent using a class extending Activity.
For example like this:
Intent i = new Intent(this, SomeActivity.class);
startActivity(i);
where this is current Context and SomeActivity is the activity you want to start.
Take a look at the docs:
http://developer.android.com/training/basics/firstapp/starting-activity.html
To call a new Activity from the current Activity you need to to pass the context of the current activity and the "NewClass" which you want to open as parameters.
For Eg :
Intent i = new Intent(CurrentClassName.this, TheClassToBeOpened.class);
startActivity(i);
IMHO using actions is overkill for what you want to achieve. You should just ude something like:
Intent i = new Intent(getContext(), RegistrationActivity.class);
startActivity(i);
(you can use this instead getContext() too).
If you do really want to use actions, then you must define the intent filter register_filter in your activity. Something along the lines:
<activity
android:name=".LoginActivity"
android:label="#string/title_activity_login"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="login_filter" />
</intent-filter>
</activity>
should do the trick.
For reference, please have a look at the documentation and this question.

How to set an image to the button using the other application package name?

Im facing a problem as below stated.
I'm having a single button on the widget.On click of the button it open other application.Now my question is how to assign that open application image to my button which is in the widget.
Please help me.
This is my Main class.
{
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.RemoteViews;
import android.widget.Toast;
public class WidgetMainProvider extends AppWidgetProvider {
// Activity a=new Activity();
public static String GET_ACTION = "Get_Action";
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
if (GET_ACTION.equals(intent.getAction())) {
Toast.makeText(context, "onReceiver()", Toast.LENGTH_LONG).show();
}
}
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
Log.i("ExampleWidget", "Updating widgets " + Arrays.asList(appWidgetIds));
// Perform this loop procedure for each App Widget that belongs to this
// provider
for (int i = 0; i < N; i++) {
int appWidgetId = appWidgetIds[i];
//Which defines the UI of Widget
// initializing widget layout
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),R.layout.widget1);
Intent intent = new Intent(context, WidgetOneActivity.class);
// intent.setAction(GET_ACTION);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
remoteViews.setOnClickPendingIntent(R.id.button,pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
}}}
This is my another class where i have declared the package name,based on that it will open the application.
package com.purvotara.example.widget;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
public class WidgetOneActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PackageInfo pkgInfo=new PackageInfo();
context.getPackageManager().getApplicationIcon(pkgInfo.packageName);
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.drdo.s.a.m.s");
startActivity(LaunchIntent);
}
}
And also please help me where to put the code which which will set image to the button dynamically.
Here is my Android. manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.eightbitcloud.example.widget"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/icon"
android:label="#string/app_name" >
<activity
android:name="com.purvotara.example.widget.WidgetOneActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="com.purvotara.example.widget.WidgetMainProvider"
android:label="#string/widget1name" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#XML/widget1_info" />
</receiver>
</application>
</manifest>
Please help me geeks,im waiting.
As I understand, you are trying to assign another app icon to your widget button. You can try:
PackageManager packageManager = mContext.getPackageManager();
Drawable icon = packageManager .getApplicationIcon("com.example.yourapp");
button.setBackgroundDrawable(icon);
or
Drawable icon = getPackageManager().getApplicationIcon("com.example.yourapp");
button.setBackgroundDrawable(icon);
I added the following in the WidgetOneActivity class:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button button = null;
//YOU NEED TO INITIALIZE YOUR BUTTON HERE, YOUR BUTTON IS NULL
try {
Drawable icon;
icon = getPackageManager().getApplicationIcon("com.drdo.s.a.m.s");
button.setBackground(icon);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.drdo.s.a.m.s");
startActivity(LaunchIntent);
}
});
}
After adding this my app is closing.

Android Splash screen to activity

I am creating an android app and when I go to debug it on my samsung galaxy the Splash activity loads first,as it should, but after that the app crashes/stops right after doing the "Splash" activity. It doesn't go to the "MainActivity" activity after the thread sleeps for 5 seconds. Does anyone know what might be causing the problem? Plus after I tried debugging the app and loaded it onto my phone the app isn't even showing up. I am using Eclipse by the way. It shows the app in my application manager on my phone but it doesn't show the icon in my app screen.
Here is my Splash.java:
package com.example.mihirsandroidapp;
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 timer = new Thread(){
public void run(){
try{
sleep(5000);
} catch (InterruptedException e){
e.printStackTrace();
}finally{
Intent openMainActivity = new Intent("com.example.mihirandroidsapp.MAINACTIVITY");
startActivity(openMainActivity);
}
}
};
timer.start();
}
#Override
protected void onPause() {
super.onPause();
finish();
}
}
Here is my Manifest:
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:debuggable="true"
android:allowBackup="true"
android:icon="#drawable/cartooncat"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.mihirsandroidapp.SPLASH" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.mihirsandroidapp.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
And here is my main activity which should start after the splash screen:
package com.example.mihirsandroidapp;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
int counter;
Button add, sub;
TextView display;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter = 0;
add = (Button) findViewById(R.id.bAdd);
sub = (Button) findViewById(R.id.bSub);
display = (TextView) findViewById(R.id.tvDisplay);
add.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
counter += 1;
display.setText("Total is " + counter);
}
});
sub.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
counter -= 1;
display.setText("Total is " + counter);
}
});
}
}
Oh.. Where do I start.. Let's go through all of the issues:
1) Fix your manifest. Definitely not the right way to declare your activities. Here is what it should look like:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:debuggable="true"
android:allowBackup="true"
android:icon="#drawable/cartooncat"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<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>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
</activity>
</application>
2) Now let's fix the way you start your activity:
Intent openMainActivity = new Intent(Splash.this, MainActivity.class);
3) Don't call finish() in onPause() - you break native activity lifecycle flow. Call finish() right after you start new activity:
Intent openMainActivity = new Intent(Splash.this, MainActivity.class);
startActivity(openMainActivity);
finish();
4) Instead of creating separate thread, just a create a Handler and post Runnable there with 5 seconds delay:
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
//this will be called after 5 seconds delay
}
}, 5000);
Here is entire file put together:
public class Splash extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
Intent openMainActivity = new Intent(Splash.this, MainActivity.class);
startActivity(openMainActivity);
finish();
}
}, 5000);
}
If it doesn't help - we definitely need to look at logcat output...
A simple way to achieve this if one is ready to compromise on drawing performance is to define custom theme with splash image that one wants to use as window background and use this custom theme as application theme
styles.xml
<resources>
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowBackground">#drawable/background_image</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
AndroidManifest.xml
<application
android:debuggable="true"
android:icon="#drawable/icon"
android:theme="#style/CustomTheme"
android:label="#string/app_name">
...
</application>
This would use the #drawable/background_image as the window.background. As a result if the activities has transparent background then #drawable/background_image will be visible as activities background. One can avoid this by setting appropriate color or drawable in onCreate of every activity programatically as
public void onCreate(){
super.onCreate(savedInstanceState);
setContentView(R.layout.layoutResID);
activity.getWindow().setBackgroundDrawableResource(R.color.window_bg);
}
Check this for more information
All what you need for a splash screen
SplashActivity.java
public class SplashActivity extends AppCompatActivity {
private final int SPLASH_DISPLAY_DURATION = 1000;
#Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
new Handler().postDelayed(new Runnable(){
#Override
public void run() {
Intent mainIntent = new Intent(SplashActivity.this,MainActivity.class);
SplashActivity.this.startActivity(mainIntent);
SplashActivity.this.finish();
}
}, SPLASH_DISPLAY_DURATION);
}}
In drawables create this bg_splash.xml
<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#color/app_color"/>
<item>
<bitmap
android:gravity="center"
android:src="#drawable/ic_in_app_logo_big"/>
</item></layer-list>
In styles.xml create a custom theme
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/bg_splash</item>
</style>
and finally in AndroidManifest.xml specify the theme to your activity
<activity
android:name=".activities.SplashActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Cheers.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Thread th = new Thread(new Runnable() { /*create a new thread */
#Override
public void run() { /*
* The purpose of this thread is to
* navigate from one class to another
* after some time
*/
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
/*
* We are creating this new thread because we don’t
* want our main thread to stop working for that
* time as our android stop working and some time
* application will crashes
*/
e.printStackTrace();
}
finally {
Intent i = new Intent(MainActivity.this,
Splash_Class.class);
startActivity(i);
finish();
}
}
});
th.start(); // start the thread
}
http://www.codehubb.com/android_splash_screen
I have added splash screen by using following code:
public class SplashActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_layout);
initConstatnts();// method for intilizing any constants
new Thread(new Runnable() {
#Override
public void run() {
if (!isFinishing()) // checking activity is finishing or not
{
try {
Thread.sleep(3000);//delay
Intent i = new Intent(getBaseContext(),
HomeActivity.class);
startActivity(i);
finish();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}).start();
}
private void initConstatnts() {
}
}
Flow the below steps to Create your own splash screen
Create Activity1 and XML file
Design the XML file and put the welcome message
Crete Activity2 and XML file.
Start the Activity1
Start a Thread in Activity1 and sleep for 5 seconds
Start Activity2 from the Thread
There is nothing called readymade splash screen in Android . we can achieve that using above steps.
In a single line, start Activity1 wait for 5 sec then start Activity2.
So user will feel that first screen is splash screen.
You can download the complete code from below link
http://javaant.com/splash-screen-android/#.VwzHz5N96Hs
i have faced the same problem.... i think you code is perfect for the app
u just try with this in the Intent Creation in your splash activity class
Intent openMainActivity = new Intent("android.intent.action.MAIN");//MAIN is the that u want to start
//next after the current Activity

PreferenceActivity and BroadcastReceiver - Implement dynamic preferences

I'm going by the following code example to dynamically build a preference activity.
http://www.linuxtopia.org/online_books/android/devguide/guide/samples/ApiDemos/src/com/example/android/apis/app/PreferencesFromCode.html
The preference dialog shows, but I'm not able to see any changes after closing it.
Here's where I'm defining the activity in AndroidManifest.xml
<activity
android:name="PreferencesActivity" android:label="#string/preferences_name">
</activity>
Here's where I'm defining the receiver.
<receiver
android:name="FroyVisualReceiver"
android:label="#string/app_name"
android:exported="false">
<intent-filter>
<action android:name="com.starlon.froyvisuals.PREFS_UPDATE"/>
</intent-filter>
</receiver>
And here's the BroadcastReceiver. I never see the "WTF" in logcat. What am I doing wrong?
package com.starlon.froyvisuals;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.Context;
import android.util.Log;
public class FroyVisualsReceiver extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent)
{
Log.e("WTFWTF", "WTFWTFWTFW");
String action = intent.getAction();
if(action.equals("com.starlon.froyvisuals.PREFS_UPDATE"))
{
((FroyVisuals)context).updatePrefs();
}
}
}
Oh here's onPause where I'm broadcasting the PREFS_UPDATE intent.I do see the logcat message. This method is part of my PreferenceActivity.
/** another activity comes over this activity */
#Override
public void onPause()
{
Log.i(TAG, "onPause ================================ ");
super.onPause();
Intent i = new Intent(this, FroyVisualsReceiver.class);
i.setAction("com.starlon.froyvisuals.PREFS_UPDATE");
sendBroadcast(i);
}
Edit: I think it may have to do with this line. 'this' points to my PreferenceActivity.
Intent i = new Intent(this, FroyVisualsReceiver.class);
Try a simple Intent:
Intent i = new Intent();
i.setAction("com.starlon.froyvisuals.PREFS_UPDATE");
sendBroadcast(i);

Categories

Resources