I have two android activities with one single button on both.
The activity DetailsActivity is my MAIN activity.
public class DetailsActivity extends Activity {
#Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.details_activity_layout);
}
#Override
public void onResume() {
super.onResume();
}
public void gotoSubDetails(View view) {
Intent intent = new Intent(this, SubDetailsActivity.class);
startActivity(intent);
finish();
}
}
And my SubDetailsActivity is as follows:
public class SubDetailsActivity extends Activity {
#Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.sub_details_activity_layout);
}
#Override
public void onResume() {
super.onResume();
}
public void gotoDetails(View view) {
Intent intent = new Intent(this, DetailsActivity.class);
startActivity(intent); // Restarting the finish()ed activity here.
finish();
}
}
And this is how I mentioned my button in details_activity_layout.xml for DetailsActivity.java:
<Button android:id="#+id/details_submit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/to_sub_details"
android:onClick="gotoSubDetails" />
And this is how I have mentioned my button in sub_details_activity_layout.xml for SubDetailsActivity.java:
<Button android:id="#+id/sub_details_submit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/back_to_details"
android:onClick="gotoDetails" />
These are my both activities in AndroidManifest.xml:
<activity android:name="DetailsActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="SubDetailsActivity">
</activity>
When I click the button in DetailsActivity, the activity finish()es properly and SubDetailsActivity starts up.
But when I click the button in SubDetailsActivity to get back to the finish()ed DetailsActivity, the app straight away crashes on my LG L90 phone.
Where am I going wrong? Any help? Please.
PS:
I cannot post the log cat report as I did not test it on my mac but directly on my phone. I don't have an emulator. I am compiling the code on my terminal and transferring the .apk file on my phone via bluetooth.
EDIT:
Ok guys. Now this is really funny!
I removed the
android:onClick="gotoSubDetails"
and
android:onClick="gotoDetails"
from my details_activity_layout.xml and sub_details_activity_layout.xml respectively. And I loaded the android.widget.Button's in my DetailsActivity.java and SubDetailsActivity.java and added an android.view.View.OnClickListener on both of them and overrode the onClick(View) method.
This is what I did in my DetailsActivity.java:
public class DetailsActivity extends Activity {
#Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.details_activity_layout);
Button button = (Button)findViewById(R.id.details_submit);
button.setOnClickListener(new DetailsSubmitListener());
}
#Override
public void onResume() {
super.onResume();
}
public class DetailsSubmitListener implements OnClickListener {
#Override
public void onClick(View view) {
Intent intent = new Intent(this, SubDetailsActivity.class);
startActivity(intent);
finish();
}
}
}
And this is what I did in my SubDetailsActivity.java class:
public class SubDetailsActivity extends Activity {
#Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.details_activity_layout);
Button button = (Button)findViewById(R.id.sub_details_submit);
button.setOnClickListener(new SubDetailsSubmitListener());
}
#Override
public void onResume() {
super.onResume();
}
public class SubDetailsSubmitListener implements OnClickListener {
#Override
public void onClick(View view) {
Intent intent = new Intent(this, DetailsActivity.class);
startActivity(intent);
finish();
}
}
}
And this miraculously worked fine.
So what was the problem with the .xml attributes in my layout files? And how different is it from the hardcoded listener in my .java file? This thing has confused me. finish()ed activities can be re-started. Thats what I discovered with my change in the program. Please shed some light of knowledge on this.
Aditya,
If you want to traverse between 2 activities like in your case, you should never finish Details activity. Instead without finishing Details activity, start SubDetails activity. If you want to come back, no coding required. If user presses BACK button, SubDetails Activity will be finished and DetailsActivity will come to foreground.
Finishing one activity and starting it again, is unnecessary overhead. Avoid it. Finish activity if it is absolutely necessary.
Also, there is no any way to restart finished activity.
Just like Harry answered,
I want to add something for you. If you are programming for higher API Levels (e.g. Android API 13+) you can define a parent activity.
This way you don't need to make such complex implementations.
For reference
Google Developers Guide to UP navigation
Stackoverflow ANSWER on the topic
I think you should read this!:
http://developer.android.com/guide/components/tasks-and-back-stack.html
I think it's very important how you declared the launchMode in your andriodManifest for your activities ! There should be the problem. Read carefully what is a task and how a back stack in android works.
Maybe you are finishing the task but at same time you are viewing the next activity which is in the same task ! After reopen it crashed because of this I think. Hope it helps.
I want to show a splashScreen on my app firstly for few seconds and then load all my threads data using timer in java, then how should i do it.
Add Splash Screen Activity to your Project...
now replace the SplashScree.java file code as :
package samples.splash.screen;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
/**
* Splash screen activity
*
* #author Catalin Prata
*/
public class SplashScreen extends Activity {
// used to know if the back button was pressed in the splash screen activity and avoid opening the next activity
private boolean mIsBackButtonPressed;
private static final int SPLASH_DURATION = 2000; // 2 seconds
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
Handler handler = new Handler();
// run a thread after 2 seconds to start the home screen
handler.postDelayed(new Runnable() {
#Override
public void run() {
// make sure we close the splash screen so the user won't come back when it presses back key
finish();
if (!mIsBackButtonPressed) {
// start the home screen if the back button wasn't pressed already
Intent intent = new Intent(SplashScreen.this, Home.class);
SplashScreen.this.startActivity(intent);
}
}
}, SPLASH_DURATION); // time in milliseconds (1 second = 1000 milliseconds) until the run() method will be called
}
#Override
public void onBackPressed() {
// set the flag to true so the next activity won't start up
mIsBackButtonPressed = true;
super.onBackPressed();
}
}
And the splash_screen xml looks like this: where you should have any image in your drawables named : "splash_screen"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/splash_screen"/>
Now make your Splash Screen a Launcher Activity in Manifest File to make it a startup Activity..
And in order to get the title bar of the application down, just add he activity in your manifest and add the theme as you can see below:
<activity android:name=".SplashScreen" android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN">
<category android:name="android.intent.category.LAUNCHER">
</category></action></intent-filter>
</activity>
Visit the following excellent tutorial on splash screen in Java(Swing).
Adding a splash screen to your application
I have an app start by Splash activity screen for 5 seconds Then open Login activity screen then after you put correct user and password open the Menu activity (listActivity) then each row click open MyCity activity.
UPDATE:
What I'm trying to get is: where ever you are in my app, and you go away from my app for any reason not only when you press the home button but also FOR EXAMPLES:
You press home button to check another app then want to return to my app .
You have notification show new message on whatsup or email, you open your whatsup or open email, then return to my app .
3- You left your mobile for period of time then you want to check my app again .
4- you press power button to close the phone ( lock the screen) , then open the lock and want to return back to my app .
what I mean any time you go away my app for any reason but whithout press back back back button which will exit the whole app
then want to return again to my app must open to
you the login screen to re enter your usename and password again.
I Called finish(); for both Splash activity and Login activity .
I tried:android:clearTaskOnLaunch="true" in the Login activity in the manifest but it doesn'thing.
Any advice will be appreciated,
PLEASE WRITE FULL WORKING CODE.
LOGIN ACTIVITY:
public class Login extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
Button b = (Button) findViewById(R.id.loginbutton);
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
EditText username = (EditText) findViewById(R.id.login);
EditText password = (EditText) findViewById(R.id.password);
if(username.getText().toString().length() > 0 && password.getText().
toString().length() > 0 ) {
if(username.getText().toString().equals("test") && password.getText().
toString().equals("test")) {
Intent intent = new Intent(Login.this, Menu.class);
startActivity(intent);
finish(); }
} }
}); } }
Menu Activity :
public class Menu extends ListActivity {
String classes[] = { "City1", "City2", "City3", "City4", "City5"};
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this,
android.R.layout.simple_list_item_1, classes));
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String cheese = classes[position];
try {
Class ourClass = Class.forName("com.test.demo.MyCity");
Intent ourIntent = new Intent(Menu.this, ourClass);
ourIntent.putExtra("cheese", cheese);
startActivity(ourIntent);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}}
MyCity Activity :
public class MyCity extends Activity {
TextView tv1;
String city;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.city);
initializeTextViews();}
private void initializeTextViews() {
tv1=(TextView)findViewById(R.id.city_tv);
city=getIntent().getStringExtra("cheese");
if(city.equalsIgnoreCase("City1")){
tv1.setText(Html.fromHtml(getString(R.string.city1)));}
else if(city.equalsIgnoreCase("City2")){
tv1.setText(Html.fromHtml(getString(R.string.city2)));}
else if(city.equalsIgnoreCase("City3")){
tv1.setText(Html.fromHtml(getString(R.string.city3)));}
else if(city.equalsIgnoreCase("City4")){
tv1.setText(Html.fromHtml(getString(R.string.city4)));}
else if(city.equalsIgnoreCase("City5")){
tv1.setText(Html.fromHtml(getString(R.string.city5)));}
}}
MY MANIFEST:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.demo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
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=".Login"
android:label="#string/app_name"
android:clearTaskOnLaunch="true">
<intent-filter>
<action android:name="com.test.demo.LOGIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Menu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.test.demo.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".MyCity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.test.demo.MYCITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
SECOND UPDATE : i reached halfway to what i want but still some steps i can't achieve it explained as below :
BY applying android:clearTaskOnLaunch="true" to Splash activity ,
and prevent back button behaviour on Menu activity :
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
moveTaskToBack(true);
return true;
}
return super.onKeyDown(keyCode, event);
} }
SO now when press home button away my app then return to my app its:
go directly to Login activity.
but main goal now is :
if :
SCREEN LOCKED when you are away from your mobile , or press lightly the power button to lock the phone .
or
OPENED MESSAGE from notification
or
OPENED EMAIL from notification
or
you have CALL and answer it ,
THEN return to my app it does not go to login activity but you will return to the page where you was befor .
ANY ADVICE PLEASE , THANKS.
THIED UPDATE :
i used another code for override home button and control the back button rather than appling :android:clearTaskOnLaunch="true" to Splash activity in manifest , just apply the down code to Menu activity:
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
moveTaskToBack(true);
return true;}
else if (keyCode == KeyEvent.KEYCODE_HOME) {
Intent i=new Intent(Menu.this,Login.class);
startActivity(i);
finish();
return true;}
return super.onKeyDown(keyCode, event);}
If I understand you right, your goal is that users have to enter username and password again, when they come back to your App. So I think the most logical way to achieve this would be to add a check in all your Activities onResume() method to see if you have a username and password and if not, simply go to the login activity. Easiest way would be to have a BaseActivity implementing the check and let all your other activities (except for spash and login) inherit from that BaseActivity.
in pseudo java code
class BaseActivity extends Activity {
onResume() {
super.onResume();
if (!havingUsernameAndPassword()) {
startActivity(loginActivity);
finish();
}
}
}
class AnyOfYourActivitiesExceptSpashAndLogin extends BaseActivity {
onResume() {
super.onResume();
// ... further code
}
// ... further code
}
The implementation of havingUsernameAndPassword() of course depends on how you store the username and password in your login activity. A very simple way would be to store them in some static class members, so they'd survive as long as the Application runs.
Update: a more concrete example
I made a new example also showing how you can save the login data on login to be able to check it later on. Actually it would make even more sense to have just a flag 'loggedIn' and some user-id, but that depends upon your implementation, so I'll stick with username/password here.
class SimpleDataHolder {
public static String username = null;
public static String password = null;
}
class LoginActivity extends Activity {
// ...
// when user has entered valid username/password, store them in SimpleDataHolder:
SimpleDataHolder.username = username; // <-- store username entered
SimpleDataHolder.password = password; // <-- store password entered
}
class BaseActivity extends Activity {
onResume() {
super.onResume();
if (SimpleDataHolder.username == null || SimpleDataHolder.password == null) {
startActivity(loginActivity); // <-- go to login
finish(); // <-- end current activity
}
}
}
class AnyOfYourActivitiesExceptSpashAndLogin extends BaseActivity {
// ... your existing code (if any)
onResume() {
super.onResume(); // <-- this calls BaseActivity.onResume() which checks username/password
// ... your existing code (if any)
}
An application CANNOT re-route the home button without modifying the framework code. Sorry this is NOT possible...
To your second update problem I would suggest overriding the OnResume() method, but you must be careful with what you do in it. I would also suggest you study on how the android lifecycle works.
This is my suggestion :
Have a key in SharedPreferences called exit. In the onCreate() set the value of exit to false
public void onCreate(Bundle ..)
{
SharedPreferences preferences=PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor=preferences.edit();
editor.putString("exit","false");
editor.commit();
.....
}
then in onResume() check the value of exit. If it is true, take the user to the login screen else do not do anything .
public void onResume()
{
super.onResume();
SharedPreferences preferences=PreferenceManager.getDefaultSharedPreferences(context);
String exit=preferences.getString("exit","");
if(exit.equals("true"))
{
Intent i=new Intent(this_activity.thi,login_activity.class);
startActivity(i);
finish()
}
}
then in onPause() set the value of exit to true.
public void onPause()
{
super.onPause();
SharedPreferences preferences=PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor=preferences.edit();
editor.putString("exit","true");
editor.commit();
}
You said that you have taken care of the backbutton. Then this should do it. Your app will always return to the login screen.
Here is the solution I came up with.
Please Download the project at the end of the blog post and test it.
Tested on:
Samsung S3 running android 4.0.4
Emulator running android 2.3.1
The basic idea: We will create a RequireLoginActivity which will be extended by all our activities except the LoginActivity.
Three cases should be captured when the onResume function is called:
Jumping from one RequireLoginActivity to another RequireLoginActivity using a flavor of startActivity.
Jumping from one RequireLoginActivity back to a previous RequireLoginActivity by finishing the current activity.
Coming back to a RequireLoginActivity after hiding it (we should here show the login!)
The basic idea of my solution is to have 2 counters: number of Started activities (startCounter) and number of Paused activities (pauseCounter). Each time an activity starts we will increment startCounter. Similarly, when an activity pauses, pauseCounter should be incremented. In our onResume function, we will decide whether to go to the Sign in by comparing the 2 counters. We will gotoLogin() if the 2 counters are equal!
Let me explain:
At any time, case 1 can be captured simply because upon starting new activities, our startCounter will always be greater that pauseCounter by 1. This is true because we will always have one extra activity started but not paused.
Also, case 3 is easily captured, because once you leave our app, say, using the HOME button, we will increment the pauseCounter and the 2 counters will become equal. Once the app is resumed, the onResume will decide to gotoLogin().
Case 2 is a bit tricky, but simple as well. The trick is by overriding the finish() function and decrementing the startCounter once and the pauseCounter twice in it. Remember that when finishing the activity, onPause is called and our counters are equal. Now by decrementing startCounter once and pauseCounter twice, we ultimately returned to the counters' values of the previous activity, and startCounter will remain greater the pauseCounter by 1 when the previous activity resumes.
Another workaround will be to create a activity(FinisherActivity) and call finish() in its onCreate() method. Then whenever you need to finish a activity on pressing the home button or back button and prevent it from staying on the stack just use an Intent to call FinisherActivity . But remember to setFlags for the intent to Intent.FLAG_ACTIVITY_CLEAR_TOP...I know its not an efficient approach, but it should work..
Actually I dont think i'm sure what exactly your asking, Do you want to press the Home Key built into your android device and start an activity?
Homekey listener
Try This:
if it works then awesome, just through an intent in there to call your login activity
#Override
public boolean dispatchKeyEvent(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.KEYCODE_HOME) {
Toast.makeText(MainActivity.this, "Home Key is pressed
Toast.LENGTH_LONG).show();
return true;
}
Toast.makeText(MainActivity.this, "Didnt work", Toast.LENGTH_SHORT)
.show();
return super.dispatchKeyEvent(e);
};
what you are asking is against the way that android works .
when the user presses the home button , he expects that when he returns to the app , everything will stay as it was before , unless he wasn't there for a long time or if he ran a resource consuming app .
it's as if on windows , when you click ALT+TAB , you won't expect to see login on the email client (or messenger , or whatever app you use) .
in any case , you can use onWindowFocusChanged together with any of the functions of activity (onResume,onStart,onRestart,onPause,onStop,...) , and handle only the relavant cases you wish to use .
it's not possible because the home button is exclusive to call launcher application, but you can do your app a launcher application, running in kiosk mode for example, see it and it.
to turn a activity on launcher activity add this on itentfilter on manifest.xml
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
You can't override the home button default behaviour. You achieve the desired result by clicking back button, Home button's default behaviour is to goto Home Screen. My suggestion Override Back Button. Then using intent and setting flags properly you can goto login screen.
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
super.onKeyDown(keyCode, event);
switch(keyCode)
{
case KeyEvent.KEYCODE_BACK:
Intent i= new Intent("yourpackage.login");
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(i);
finish();
break;
}
return super.onKeyDown(keyCode, event);
}
It is difficult to tell exactly what you are asking, however I believe this is what you are looking for: How to make splash screen not to load if app is already in memory . To summarize my post there:
This is a design problem. Your launcher activity should not be your splash screen activity. Instead, open your splash activity in your main activity's onCreate method. That way, if it is opened fresh, onCreate is called and the splash screen is shown. Otherwise, if the app is merely resumed, which calls onResume, there would be no call to open the splash screen activity.
Then you can change your manifest to this:
<activity
android:name=".ui.MainActivity"
android:noHistory="true"
android:screenOrientation="portrait"
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=".ui.SplashActivity"/>
Have you tried the android:noHistory activity attribute (for each of your activities) in the Android Manifest? That sounds like exactly what you are looking for.
Your code is almost correct: to clear the activity stack when launching your application, you should add android:clearTaskOnLaunch="true" to your root activity, which is Splash, not Login (it will be the first one running, see this question on determining the root activity)!
From the documentation:
This attribute is meaningful only for activities that start a new task
(the root activity); it's ignored for all other activities in the
task.
So if you move the attribute in the manifest from Login to Splash, it should work, your application will always start with the splashscreen.
UPDATE: To restart your app even on incoming calls, screen lock or notifications, you have to add android:noHistory="true" (docs here) to all your other activities, or call finish() in all their onPause() methods.
It's worth mentioning that our answers are so different and complicated because what you want to achieve is totally against core Android concepts (for example, here is a good article on exiting apps), so really, don't do anything like this outside your private app.
You should call finish() in all your activities' onPause() methods except Login activity. And you can call startActivity(new Intent (this, LoginPage.this)) in their onResume() method. So whenever the activities will come to foreground, user will be redirected to Login page again.
My little efforts may helps you, I had successfully Override the HOME button(below Android 4.0)
You can mould the code according to your requirement.
Answer on SO
Source at GITHUB
As you can now handle Home button so you can easily create your own logic to perform you Application flow.
this is you targetted event
#Override
public boolean dispatchKeyEvent(KeyEvent event) {
if ( (event.getKeyCode() == KeyEvent.KEYCODE_HOME) && isLock) {
//Logic when Home button pressed
return true;
}
else
return super.dispatchKeyEvent(event);
}
Hoping this will definitely going to meet our requirements.
Note: All this is for capturing Home Button for others you can manage
i have this code but every time i run the app and click on my button it crashes and i don't get why.. am i doing something wrong here any help would be great thanks
im trying to got to the "Sec.class" page/class
public class APPcalendarActivity extends Activity implements OnClickListener{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View continueButton = findViewById(R.id.continue_button);
continueButton.setOnClickListener( (OnClickListener) this);
}
//#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.continue_button:
Intent i = new Intent(this, Sec.class);
startActivity(i);
break;
}
}
THIS IS WHAT I WAS MISSING IN THE MANISFEST.XML FILE
and i want to slap the person who downgraded my question
<activity android:name=".Sec"
android:label="#string/sec" >
</activity>
Check that you've declared an <activity> tag for the Sec activity in your AndroidManifest.xml.
But posting (or simply reading) the crash stacktrace from logcat would be more instructive.
Without knowing what the error is, it is really hard to guess what the problem is, but usually when this happens, the button (continueButton in your case) could not be found in the layout. So make sure that you have a View with id continue_button in main.xml.
I am working on an android app that has two activities. One is the menu screen and the other is the one that the user actually uses once they have made a selection. The second activity does all of its processing in a worker thread. When I make the selection to move on to the second activity, it "flashes" the activity for about 100ms. I found some logs that look like they would tell me what I need to fix if I knew what they meant.
02-29 10:52:33.850: I/ActivityManager(1255): Starting activity: Intent { cmp=com.wcf.imageShare/.ImageShareActivity }
02-29 10:52:33.920: W/InputManagerService(1255): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy#45c0a198 (uid=10097 pid=24918)
02-29 10:52:33.936: W/WindowManager(1255): No window to dispatch pointer action
02-29 10:52:33.952: I/ActivityManager(1255): Displayed activity com.wcf.imageShare/.ImageShareActivity: 96 ms (total 96 ms)
02-29 10:52:34.000: W/WindowManager(1255): No window to dispatch pointer action 1
The program itself is not crashing, it just takes me back to the menuview and displays my choices again. Here is the code I am using to switch activities
lstServers.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Beacon.activeServer = position;
Intent uploadIntent = new Intent(inst,ImageShareActivity.class);
inst.startActivity(uploadIntent);
}
});
inst holds the 'this' variable of the activity that the code is running in since I couldn't reference it by using 'this'
Here is the onCreate of the activity I am trying to switch to:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try
{
progBar = (ProgressBar)findViewById(R.id.progressbar_Horizontal);
tv = (TextView)findViewById(R.id.prog_txt);
btnCancel = (Button)findViewById(R.id.cancel);
btnCancel.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
try {
uploaderThread.interrupt();
Uploader.CancelUpload();
} catch (Exception e) {
e.printStackTrace();
}
}
});
uploaderThread.start();
}
catch(Exception e)
{
Log.d("Uploader ERROR",e.getMessage());
}
}
And finally the part of the manifest file that has to do with the two activities.
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" android:debuggable="true">
<activity
android:name=".ImageShareActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
</activity>
<activity android:name=".ServerChoiceActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<data android:mimeType="image/*"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
Does anyone have any suggestions or know of something that I am missing?
Thanks
Nick Long
Change this to this :
lstServers.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Beacon.activeServer = position;
Intent uploadIntent = new Intent(your_current_activty.this,ImageShareActivity.class);
uploadIntent.startActivity();
}
});