Search Results

Search found 107 results on 5 pages for 'onresume'.

Page 1/5 | 1 2 3 4 5  | Next Page >

  • Setting spinners onResume doesn't work

    - by DixieFlatline
    Hello! I want to save text from 2 edittexts(et1,et2) and selection from 3 spinners(spinnerm,spinner and spinner2) onPause and setting them back onResume. Text from edittexts is saved correctly, only spinner selection don't work as desired. My code: public void onResume(){ super.onResume(); Log.d("REZUM","notr smo"); SharedPreferences seti = getSharedPreferences( "pavzica", MODE_PRIVATE); spinnerm.setSelection(seti.getInt("m", 0)); spinner.setSelection(seti.getInt("k", 0)); spinner2.setSelection(seti.getInt("p", 0)); et1.setText(seti.getString("zade", "")); et2.setText(seti.getString("Vseb", "")); } public void onPause() { shraniPolja(); super.onPause(); } public void shraniPolja() { SharedPreferences seti = getSharedPreferences( "pavzica", MODE_PRIVATE); SharedPreferences.Editor edito = seti.edit(); edito.putString("zade", et1.getText().toString()); edito.putString("Vseb", et2.getText().toString()); edito.putInt("m", spinnerm.getSelectedItemPosition()); edito.putInt("k", spinner.getSelectedItemPosition()); edito.putInt("p", spinner2.getSelectedItemPosition()); edito.putBoolean("b", true); edito.commit(); } What am i doing wrong?

    Read the article

  • Android lifecycle: Fill in data in activity in onStart() or onResume()?

    - by pjv
    Should you get data via a cursor and fill in the data on the screen, such as setting the window title, in onStart() or onResume()? onStart() would seem the logical place because after onStart() the Activity can already be displayed, albeit in the background. Notably I was having a problem with a managed dialog that made me rethink this. If the user rotates the screen while the dialog is still open, onCreateDialog() and onPrepareDialog() are called between onStart() and onResume(). If the dialog needs to be based on the data you need to have the data before onResume(). If I'm correct about onStart() then why does the Notepad example give a bad example by doing it in onResume()? See http://developer.android.com/resources/samples/NotePad/src/com/example/android/notepad/NoteEditor.html NoteEditor.java line 176 (title = mCursor.getString...). Also, what if my Activity launches another Actvity/Dialog that changes the data my cursor is tracking. Even in the simplest case, does that mean that I have to manually update my previous screen (a listener for a dialog in the main activity), or alternatively that I have to register a ContentObserver, since I'm no longer updating the data in onResume() (though I could update it twice of course)? I know it's a basic question but the dialog only recently, to my surprise, made me realize this.

    Read the article

  • onPause/onResume activity issues

    - by Josh
    I have a small test application I am working on which has a timer that updates a textview to countdown from 100 to 0. That works fine, but now I am trying to pause the application if the user presses the back button on the phone and then restart the timer from where they left off when they reopen the app. Here is the code I am using: @Override public void onPause() { if(this._timer_time_remaining > 0) { this.timer.cancel(); } super.onPause(); Log.v("Pausing", String.format("Pausing with %d", this._timer_time_remaining)); } @Override public void onResume() { super.onResume(); Log.v("Resuming", String.format("Resuming with %d", this._timer_time_remaining)); if(this._timer_time_remaining > 0) { setContentView(R.layout.in_game); start_timer(this._timer_time_remaining); } } The start_timer() method creates a CountDownTimer which updates the textview in the onTick method and updates the this._timer_time_remaining int variable. CountDownTimer and _timer_time_remaining are both declared at the class level like this: private CountDownTimer timer; private int _timer_time_remaining; From the Log.v() prints I see that the _timer_time_remaining variable has the correct number of seconds stored when onPause is called, but it is set back to 0 when onResume starts. Why does the variable get reset? I thought that the application would continue to run in the background with the same values. Am I missing something? This is all declared in a class that extends Activity. Thanks in advance!

    Read the article

  • android existing activity read intent of file from OnResume

    - by manhon
    I have associated my app with txt file. So user can select a file in File explorer app and select my app to open it. In OnCreate: Intent intent = getIntent(); String action = intent.getAction(); if (action != null && action.equals(Intent.ACTION_VIEW)) { txtFilePath = intent.getData().getPath(); } However, when user did not close my app, and he goes back to file explorer and open another file, OnCreate is not called. OnResusme is called instead. I put below code in OnResume: Intent intent = getIntent(); String action = intent.getAction(); if (action != null && action.equals(Intent.MAIN)) { txtFilePath = intent.getData().getPath(); } However, txtFilePath is null. Why? Thank a lot for help.

    Read the article

  • MyLocationOverlay dissappears, is not there onResume.

    - by Paul
    I have a mapView to which I add a MyLocationOverlay. It displays fine when the app starts from scratch (goes through onCreate). If I exit the app (back button) and then start it again (onResume), the overlay is gone. I have tried to fix this for 10+ hours. All sorts of messing with re-adding the overlay. Resetting the overlays. Changing the maps location so it's forced to redraw. Trying to manually invalidate or force a redraw of the overlay. NOTHING has worked. From the way the code looks, the Overlay object exists and everything is working fine - but it's just not on the map. Is anybody else having this problem? (Droid Incredible, 2.2)

    Read the article

  • how to pass a string to an already opened activity?

    - by Hossein Mansouri
    I have 3 Activities A1,A2,A3 A1 call A2 (A1 goes to stack) A2 call A3 (A2 also goes to stack) And A3 call A1 (A1 should call from stack not new instance...) I don't want to Create new instance of A1 just i want to call it from stack I want to send some Extra String to A1, the problem is here, when i send some String by using putExtra() to A1, A1 can not seen it! I put getIntent() in onResume() for A1 but it s not working... Code in A3 Intent in = new Intent(A3.this,A1.class); in.putExtra("ACTIVITY", "A3"); in.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(in); Code in A1 @Override protected void onResume() { super.onResume(); if(getIntent().getExtras().getString("ACTIVITY")=="A3"){ new LoadAllMyOrders().execute(); }else{ new LoadAllMyshops().execute(); } }

    Read the article

  • What's happening between onResume and the activity is really displayed?

    - by Johnny
    I didn't nothing in the onResume of my Activity, but it still takes about 5 seconds between the onResume is called and the activity is really displayed. What's happening under there? Here is the code snip: onResume: @Override protected void onResume() { Log.d(TAG, "on resume >>>"); super.onResume(); } logcat: 05-28 10:36:05.621 D/LoginDialogActivity( 447): on resume >>> 05-28 10:36:06.231 I/ARMAssembler( 52): generated scanline__00000077:03010104_00000004_00000000 [ 22 ipp] (41 ins) at [0x3e3358:0x3e33fc] in 5646001 ns 05-28 10:36:10.690 I/ActivityManager( 52): Displayed activity com.aimi.appstore/.ui.activity.LoginDialogActivity: 5169 ms (total 5331 ms) AndroidManifest.xml: <activity android:name=".ui.activity.LoginDialogActivity" android:theme="@android:style/Theme.Dialog" />

    Read the article

  • Android - How can I access a View object instantiated in onCreate in onResume?

    - by Chris
    In my onCreate() method, I'm instantiating an ImageButton View: public void onCreate(Bundle savedInstanceState) { Log.d(AntengoApplication.LOG_TAG, "BrowsePicture onCreate"); super.onCreate(savedInstanceState); setContentView(R.layout.layout_post); final ImageButton ib = (ImageButton) findViewById(R.id.post_image); ... In onResume, I want to be able to change the properties of the ImageButton with something like: @Override protected void onResume() { super.onResume(); ib.setImageURI(selectedImageUri); } //END onResume But onResume doesn't have access to the ib ImageButton object. If this were a variable, I'd simple make it a class variable, but Android does not allow you to define View object in the class. Any suggestions on how to do this?

    Read the article

  • Android back button does not restart activity?

    - by Chris
    My app intiates an activity. On the click of a button, the app opens up the browser with a webpage. When I hit the back button, it comes back to my initial activity screen, but does not resume or restart the activity. When I put all the layout code and activity code in onResume instead of onCreate, the activity gets restarted. My question is whether this is the right way to go about it? Can I use onResume to draw my layout and initiate the activity, or is this poor design? When the browser fires up, does the initial activity forget its layout? Please let me know what you suggest. Thanks Chris

    Read the article

  • Nested fragments survive screen rotation

    - by ievgen
    I've faced with an issue with Nested Fragments in Android. When I rotate the screen the Nested Fragments survive somehow. I've come up with a sample example to illustrate this issue. public class ParentFragment extends BaseFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_parent, container); } @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); getChildFragmentManager() .beginTransaction() .add(getId(), new ParentFragmentChild(), ParentFragmentChild.class.getName()) .commit(); } @Override public void onResume() { super.onResume(); log.verbose("onResume(), numChildFragments: " + getChildFragmentManager().getFragments().size()); } } public class ParentFragmentChild extends BaseFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_child, null); } } BaseFragment just logs method calls. This is what I see when I rotate the screen. When Activity initially appears ParentFragment? onAttach(): ParentFragment{420d0a98 #0 id=0x7f060064} ParentFragment? onCreate() ParentFragment? onViewCreated() ParentFragmentChild? onAttach(): ParentFragmentChild{420d08d0 #0 id=0x7f060064 com.kinoteatr.ua.filmgoer.test.ParentFragmentChild} ParentFragmentChild? onCreate() ParentFragmentChild? onViewCreated() ParentFragment? onResume() ParentFragment? onResume(), numChildFragments: 1 ParentFragmentChild? onResume() Screen rotation #1 ParentFragmentChild? onPause() ParentFragment? onPause() ParentFragment? onSaveInstanceState() ParentFragmentChild? onSaveInstanceState() ParentFragmentChild? onStop() ParentFragment? onStop() ParentFragmentChild? onDestroyView() ParentFragment? onDestroyView() ParentFragmentChild? onDestroy() ParentFragmentChild? onDetach() ParentFragment? onDestroy() ParentFragment? onDetach() ParentFragment? onAttach(): ParentFragment{4211bc38 #0 id=0x7f060064} ParentFragment? onCreate() ParentFragmentChild? onAttach(): ParentFragmentChild{420f4180 #0 id=0x7f060064 com.kinoteatr.ua.filmgoer.test.ParentFragmentChild} ParentFragmentChild? onCreate() ParentFragment? onViewCreated() ParentFragmentChild? onViewCreated() ParentFragmentChild? onAttach(): ParentFragmentChild{42132a08 #1 id=0x7f060064 com.kinoteatr.ua.filmgoer.test.ParentFragmentChild} ParentFragmentChild? onCreate() ParentFragmentChild? onViewCreated() ParentFragment? onResume() ParentFragment? onResume(), numChildFragments: 2 ParentFragmentChild? onResume() ParentFragmentChild? onResume() Screen rotation #2 ParentFragmentChild? onPause() ParentFragmentChild? onPause() ParentFragment? onPause() ParentFragment? onSaveInstanceState() ParentFragmentChild? onSaveInstanceState() ParentFragmentChild? onSaveInstanceState() ParentFragmentChild? onStop() ParentFragmentChild? onStop() ParentFragment? onStop() ParentFragmentChild? onDestroyView() ParentFragmentChild? onDestroyView() ParentFragment? onDestroyView() ParentFragmentChild? onDestroy() ParentFragmentChild? onDetach() ParentFragmentChild? onDestroy() ParentFragmentChild? onDetach() ParentFragment? onDestroy() ParentFragment? onDetach() ParentFragment? onAttach(): ParentFragment{42122a48 #0 id=0x7f060064} ParentFragment? onCreate() ParentFragmentChild? onAttach(): ParentFragmentChild{420ffd48 #0 id=0x7f060064 com.kinoteatr.ua.filmgoer.test.ParentFragmentChild} ParentFragmentChild? onCreate() ParentFragmentChild? onAttach(): ParentFragmentChild{420fffa0 #1 id=0x7f060064 com.kinoteatr.ua.filmgoer.test.ParentFragmentChild} ParentFragmentChild? onCreate() ParentFragment? onViewCreated() ParentFragmentChild? onViewCreated() ParentFragmentChild? onViewCreated() ParentFragmentChild? onAttach(): ParentFragmentChild{42101488 #2 id=0x7f060064 com.kinoteatr.ua.filmgoer.test.ParentFragmentChild} ParentFragmentChild? onCreate() ParentFragmentChild? onViewCreated() ParentFragment? onResume() ParentFragment? onResume(), numChildFragments: 3 ParentFragmentChild? onResume() ParentFragmentChild? onResume() ParentFragmentChild? onResume() They keep getting multiplied. Does anybody know why is that ?

    Read the article

  • Android: Dialog themed activity not visible

    - by Vincent
    I have an activity which, when started, needs to check if the user is authenticated. If not, I need to display an interface to authenticate. I do this with another activity, which has a dialog theme, and I start it in onResume() with flags NO_HISTORY and EXCLUDE_FROM_RECENTS. Everything works fine when starting the application for the first time. But I have a feature that resets login after some time, if the user is not in an activity. When I test this, I start the applicatio, enter the password, then move back to home. Then when I enter the application again, the background darkens as if the dialog would show, but it doesn't. At this point, if I press the back button, the darkening from the background activity disappears for a second, then the dialog finally appears. I used logcat to investigate the case, and the activity lifecycle functions get called properly: //For the first start: onCreate background activity onStart background activity onResume background activity onPause background activity onCreate dialog onStart dialog onResume dialog //Enter password onPause dialog onResume background activity onStop dialog onDestroy dialog //navigating to homescreen onPause background activity onStop background activity //starting again onRestart background activity onStart background activity onResume background activity onPause background activity onCreate dialog onStart dialog onResume dialog //no dialog shown, only darkened background activity recieving no input //pressing back button onPause dialog onResume background activity onPause background activity onCreate NEW dialog onStart NEW dialog onResume NEW dialog onStop OLD dialog onDestroy OLD dialog //now the dialog is properly shown //entering password onPause NEW dialog onResume background activity onStop NEW dialog onDestroy NEW dialog Using the SINGLE_TOP flag makes no change. However, if I remove the dialog theme from the dialog activity, it IS shown after the restart. So far I didn't want to use a Dialog instead of an Activity, because I consider them problematic sometimes and less encapsulated and this part has to be quite secure. You may be able to convince me though.. Thank you in advance!

    Read the article

  • How do I pass data from a BroadcastReceiver through to an Activity being started?

    - by Tom Hume
    I've got an Android application which needs to be woken up sporadically throughout the day. To do this, I'm using the AlarmManager to set up a PendingIntent and have this trigger a BroadcastReceiver. This BroadcastReceiver then starts an Activity to bring the UI to the foreground. All of the above seems to work, in that the Activity launches itself correctly; but I'd like the BroadcastReceiver to notify the Activity that it was started by the alarm (as opposed to being started by the user). To do this I'm trying, from the onReceive() method of the BroadcastReceiver to set a variable in the extras bundle of the intent, thus: Intent i = new Intent(context, MyActivity.class); i.putExtra(wakeupKey, true); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); In the onResume() method of my Activity, I then look for the existence of this boolean variable: protected void onResume() { super.onResume(); String wakeupKey = "blah"; if (getIntent()!=null && getIntent().getExtras()!=null) Log.d("app", "onResume at " + System.currentTimeMillis() + ":" + getIntent().getExtras().getBoolean(wakeupKey)); else Log.d("app", "onResume at " + System.currentTimeMillis() + ": null"); } The getIntent().getExtras() call in onResume() always returns null - I don't seem to be able to pass any extras through at all in this bundle. If I use the same method to bind extras to the PendingIntent which triggers the BroadcastReceiver however, the extras come through just fine. Can anyone tell me what's different about passing a bundle from a BroadcastReceiver to an Activity, as opposed to passing the bundle from an Activity to a BroadcastReceiver? I fear I may be doing something very very obvious wrong here...

    Read the article

  • Pause and Resume and get the value of a countdown timer by savedInstanceState [closed]

    - by Catherine grace Balauro
    I have developed a countdown timer and I am not sure how to pause and resume the timer as the TextView for the timer is being clicked. Click to start then click again to pause and to resume, click again the timer's text view. This is my code: Timer = (TextView)this.findViewById(R.id.time); //TIMER Timer.setOnClickListener(TimerClickListener); counter = new MyCount(600000, 1000); }//end of create private OnClickListener TimerClickListener = new OnClickListener() { public void onClick(View v) { updateTimeTask(); } private void updateTimeTask() { if (decision==0){ counter.start(); decision=1;} else if(decision==2){ counter.onResume1(); decision=1; } else{ counter.onPause1(); decision=2; }//end if }; }; class MyCount extends CountDownTimer { public MyCount(long millisInFuture, long countDownInterval) { super(millisInFuture, countDownInterval); }//MyCount public void onResume1(){ onResume(); } public void onPause1() { onPause();} public void onFinish() { Timer.setText("00:00"); p1++; if (p1<=4){ TextView PScore = (TextView) findViewById(R.id.pscore); PScore.setText(p1 + ""); }//end if }//finish public void onTick(long millisUntilFinished) { Integer milisec = new Integer(new Double(millisUntilFinished).intValue()); Integer cd_secs = milisec / 1000; Integer minutes = (cd_secs % 3600) / 60; Integer seconds = (cd_secs % 3600) % 60; Timer.setText(String.format("%02d", minutes) + ":" + String.format("%02d", seconds)); //long timeLeft = millisUntilFinished / 1000; }//on tick }//class MyCount protected void onResume() { super.onResume(); //handler.removeCallbacks(updateTimeTask); //handler.postDelayed(updateTimeTask, 1000); }//onResume @Override protected void onPause() { super.onPause(); //do stuff }//onPause I am only beginner in android programming and I don't know how to get the value of the countdown timer using savedInstanceState. How do I do this?

    Read the article

  • Android Game Development. Async Task. Loading Bitmap Images Sounds

    - by user2534694
    Im working on this game for android. And wanted to know if my thread architecture was right or wrong. Basically, what is happening is, i am loading All the bitmaps,sounds etc in the initializevariables() method. But sometimes the game crashes and sometimes it doesnt. So i decided to use async task. But that doesnt seem to work either (i too loads at times and crashes at times) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setFullScreen(); initializeVariables(); new initVariables().execute(); // setContentView(ourV); } private void setFullScreen() { requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON ); } private void initializeVariables() { ourV=new OurView(this); stats = getSharedPreferences(filename, 0); ballPic = BitmapFactory.decodeResource(getResources(), R.drawable.ball5); platform = BitmapFactory.decodeResource(getResources(), R.drawable.platform3); gameB = BitmapFactory.decodeResource(getResources(), R.drawable.game_back2); waves = BitmapFactory.decodeResource(getResources(), R.drawable.waves); play = BitmapFactory.decodeResource(getResources(), R.drawable.play_icon); pause = BitmapFactory.decodeResource(getResources(), R.drawable.pause_icon); platform2 = BitmapFactory.decodeResource(getResources(), R.drawable.platform4); countdown = BitmapFactory.decodeResource(getResources(), R.drawable.countdown); bubbles = BitmapFactory.decodeResource(getResources(), R.drawable.waves_bubbles); backgroundMusic = MediaPlayer.create(this, R.raw.music); jump = MediaPlayer.create(this, R.raw.jump); click = MediaPlayer.create(this, R.raw.jump_crack); sm = (SensorManager) getSystemService(SENSOR_SERVICE); acc = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); sm.registerListener(this, acc, SensorManager.SENSOR_DELAY_GAME); ourV.setOnTouchListener(this); dialog = new Dialog(this,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen); dialog.setContentView(R.layout.pausescreen); dialog.hide(); dialog.setOnDismissListener(this); resume = (Button) dialog.findViewById(R.id.bContinue); menu = (Button) dialog.findViewById(R.id.bMainMenu); newTry = (Button) dialog.findViewById(R.id.bNewTry); tv_time = (TextView) dialog.findViewById(R.id.tv_time); tv_day = (TextView) dialog.findViewById(R.id.tv_day); tv_date = (TextView) dialog.findViewById(R.id.tv_date); resume.setOnClickListener(this); menu.setOnClickListener(this); newTry.setOnClickListener(this); } @Override protected void onResume() { //if its running the first time it goes in the brackets if(firstStart) { ourV.onResume(); firstStart=false; } } Now what onResume in ourV does is , its responsible for starting the thread //this is ourV.onResume public void onResume() { t=new Thread(this); isRunning=true; t.start(); } Now what I want is to initialise all bitmaps sounds etc in the async background method public class initVariables extends AsyncTask<Void, Integer, Void> { ProgressDialog pd; @Override protected void onPreExecute() { pd = new ProgressDialog(GameActivity.this); pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); pd.setMax(100); pd.show(); } @Override protected Void doInBackground(Void... arg0) { synchronized (this) { for(int i=0;i<20;i++) { publishProgress(5); try { Thread.sleep(89); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return null; } @Override protected void onProgressUpdate(Integer... values) { pd.incrementProgressBy(values[0]); } @Override protected void onPostExecute(Void result) { pd.dismiss(); setContentView(ourV); } } Now since I am new to this. You could tellme maybe if async is not required for such stuff and there is another way of doing it normally.

    Read the article

  • Calling notifyDataSetChanged doesn't fire onContentChanged event of SimpleCursorAdapter

    - by Pentium10
    I have this scenario onResume of an activity: @Override protected void onResume() { if (adapter1!=null) adapter1.notifyDataSetChanged(); if (adapter2!=null) adapter2.notifyDataSetChanged(); if (adapter3!=null) adapter3.notifyDataSetChanged(); super.onResume(); } Adapter has been defined as: public class ListCursorAdapter extends SimpleCursorAdapter { Cursor c; /* (non-Javadoc) * @see android.widget.CursorAdapter#onContentChanged() */ @Override protected void onContentChanged() { // this is not called if (c!=null) c.requery(); super.onContentChanged(); } } And the onContentChanged event is not fired, although the onResume and the call to the adapter is issued. What is wrong?

    Read the article

  • Reloading Resources on Resume

    - by Siddharth
    I'm having a problem with my game. If I press the "Home button" the game is paused... everythings fine, but if I then go back to the game all the resources are reloaded before I can continue the game. And it takes quite a bit. Is this normal, or is there a way to avoid the reloading? I have write following code in onResume and onPause method. It loads same texture again and again on resume of game. @Override protected void onPause() { super.onPause(); if (Utility.flagSound && mScene != null) { if (mScene.getUserData().equals(Constants.GAME_SCENE)) Utility.isPlayLevelMusic = false; else Utility.isPlayLevelMusic = true; audioManager.gameBgMusic.pause(); audioManager.levelBgMusic.pause(); } if (this.mEngine != null && this.mEngine.isRunning()) { this.mEngine.stop(); } } @Override protected void onResume() { super.onResume(); if (audioManager != null && Utility.flagSound && dataManager != null) { if (Utility.flagSound) { if (Utility.isPlayLevelMusic) audioManager.levelBgMusic.play(); else audioManager.gameBgMusic.play(); } } if (this.mEngine != null && !this.mEngine.isRunning()) { this.mEngine.start(); } } I would be glad if anybody could help...

    Read the article

  • Android App crashing on Back Button (performResumeActivity)

    - by Rutger
    My App consists of 2 Activities at the moment. . the MAIN activity with a Gallery View . a FriendsListActivity with a ListView When the user moves away from the FriendsListActivity with the back button, and returns to the MAIN activity the following error keeps popping up in debug mode. DalvikVM[localhost:8676] Thread [<1 main] (Suspended (exception RuntimeException)) ActivityThread.performResumeActivity(IBinder, boolean) line: 2095 ActivityThread.handleResumeActivity(IBinder, boolean, boolean) line: 2110 BinderProxy(ActivityThread$H).handleMessage(Message) line: 954 ActivityThread$H(Handler).dispatchMessage(Message) line: 99 Looper.loop() line: 123 ActivityThread.main(String[]) line: 3647 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 507 ZygoteInit$MethodAndArgsCaller.run() line: 839 ZygoteInit.main(String[]) line: 597 NativeStart.main(String[]) line: not available [native method] Thread [<8 Binder Thread #2] (Running) Thread [<7 Binder Thread #1] (Running) With the LogCat 03-13 22:01:10.972: ERROR/AndroidRuntime(1038): FATAL EXCEPTION: main 03-13 22:01:10.972: ERROR/AndroidRuntime(1038): java.lang.RuntimeException: Unable to resume activity {com.package.MAIN/com.package.MAIN.MAIN}: java.lang.NullPointerException 03-13 22:01:10.972: ERROR/AndroidRuntime(1038): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2095) 03-13 22:01:10.972: ERROR/AndroidRuntime(1038): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2110) 03-13 22:01:10.972: ERROR/AndroidRuntime(1038): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:954) 03-13 22:01:10.972: ERROR/AndroidRuntime(1038): at android.os.Handler.dispatchMessage(Handler.java:99) 03-13 22:01:10.972: ERROR/AndroidRuntime(1038): at android.os.Looper.loop(Looper.java:123) 03-13 22:01:10.972: ERROR/AndroidRuntime(1038): at android.app.ActivityThread.main(ActivityThread.java:3647) 03-13 22:01:10.972: ERROR/AndroidRuntime(1038): at java.lang.reflect.Method.invokeNative(Native Method) 03-13 22:01:10.972: ERROR/AndroidRuntime(1038): at java.lang.reflect.Method.invoke(Method.java:507) 03-13 22:01:10.972: ERROR/AndroidRuntime(1038): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 03-13 22:01:10.972: ERROR/AndroidRuntime(1038): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 03-13 22:01:10.972: ERROR/AndroidRuntime(1038): at dalvik.system.NativeStart.main(Native Method) 03-13 22:01:10.972: ERROR/AndroidRuntime(1038): Caused by: java.lang.NullPointerException 03-13 22:01:10.972: ERROR/AndroidRuntime(1038): at com.package.MAIN.MAIN.onResume(MAIN.java:91) 03-13 22:01:10.972: ERROR/AndroidRuntime(1038): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1149) 03-13 22:01:10.972: ERROR/AndroidRuntime(1038): at android.app.Activity.performResume(Activity.java:3833) 03-13 22:01:10.972: ERROR/AndroidRuntime(1038): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2085) 03-13 22:01:10.972: ERROR/AndroidRuntime(1038): ... 10 more Further info in the Variables panel states: this: ActivityThread e: NullPointerException cause: NullPointerException detailMessage: null stackTrace: null r: ActivityThread$ActivityClientRecord activity: MAIN detailMessage after one Eclipse Resume: Unable to resume activity (MAIN) The code from the FriendsListActivity looks like this public class FriendsListActivity extends ListActivity { // =========================================================== // Fields // =========================================================== private ArrayList<Friend> friends = new ArrayList<Friend>(); private FriendsArrayAdapter friendsArrayAdapter; private ListView listView; // =========================================================== // onCreate // =========================================================== @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.friends_list); registerForContextMenu(getListView()); setButtonNewFriendClickListener(); } public void generateFriendsList() { FriendsService fs = new FriendsService(this); friends = fs.getFriendsList(); listView = (ListView) findViewById(android.R.id.list); friendsArrayAdapter = new FriendsArrayAdapter( this, R.layout.friend_list_item, friends); listView.setAdapter(friendsArrayAdapter); } @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.friends_context_menu, menu); } @Override public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); FriendsService fs = new FriendsService(this); Friend f = new Friend(); f = friends.get(info.position); switch (item.getItemId()) { case R.id.edit: Intent i = new Intent(this, FriendEditActivity.class); i.putExtra("userid", f.userId); startActivity(i); return true; case R.id.delete: fs.deleteFriend(f.userId); generateFriendsList(); return true; default: return super.onContextItemSelected(item); } } // =========================================================== // onPause // =========================================================== protected void onPause() { super.onPause(); finish(); } // =========================================================== // onResume // =========================================================== protected void onResume() { super.onResume(); generateFriendsList(); } // =========================================================== // onStop // =========================================================== protected void onStop() { super.onStop(); } // =========================================================== // onDestroy // =========================================================== @Override protected void onDestroy() { super.onDestroy(); } // =========================================================== // Activity methods // =========================================================== private void setButtonNewFriendClickListener() { Button clickButton = (Button)findViewById(R.id.button_add_friend); clickButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent i = new Intent(v.getContext(), FriendNewActivity.class); startActivity(i); } }); } The AndroidManifest looks like this <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.package.mypackage"> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name="com.package.mypackage.mypackage" 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=".FriendsListActivity"></activity> <activity android:name=".FriendEditActivity"></activity> <activity android:name=".FriendNewActivity"></activity> <activity android:name=".TakePictureActivity"></activity> <activity android:name=".FriendsService"></activity> <activity android:name=".MyService"></activity> </application> <uses-sdk android:minSdkVersion="9" /> The MAIN activity looks like this: package com.package.mypackage; import java.util.ArrayList; import com.package.domain.Domain; import com.package.service.MyService; import com.package.viewadapter.myImageAdapter; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.Window; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemLongClickListener; import android.widget.Button; import android.widget.Gallery; import android.widget.Toast; public class myActivity extends Activity { // =========================================================== // Fields // =========================================================== private MyImageAdapter myImageAdapter; private ArrayList<Domain> domain = new ArrayList<Domain>(); // =========================================================== // onCreate // =========================================================== @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); /* Set Buttons to listen for any click event. */ setButtonFriendsClickListener(); setButtonCameraClickListener(); setButtonPreferencesClickListener(); } // =========================================================== // onStart // =========================================================== @Override public void onStart() { super.onStart(); /* Find the gallery defined in the main.xml */ Gallery g = (Gallery) findViewById(R.id.gallery); /* Show a Toast message when image is clicked */ g.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { MyImageAdapter image_ID = new MyImageAdapter(myActivity.this, position, null); if (image_ID.getItemId(position) == 0) { Toast test_toast = Toast.makeText(myActivity.this, "This is the New Image click", Toast.LENGTH_SHORT); test_toast.show(); } else { Toast test_toast = Toast.makeText(myActivity.this, "The clicked image has image number " + image_ID.getItemId(position) + " in the imageadapter.", Toast.LENGTH_SHORT); test_toast.show(); } } }); g.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View v, int position, long id) { MyImageAdapter image_ID = new MyImageAdapter(myActivity.this, position, null); Toast test_toast = Toast.makeText(myActivity.this, "The long clicked image has image number " + image_ID.getItemId(position) + " in the imageadapter.", Toast.LENGTH_SHORT); test_toast.show(); return true; } }); } // =========================================================== // onPause // =========================================================== protected void onPause() { super.onPause(); } // =========================================================== // onResume // =========================================================== protected void onResume() { super.onResume(); generateMyGallery(); } // =========================================================== // onStop // =========================================================== protected void onStop() { super.onStop(); } // =========================================================== // onDestroy // Is also called when user changes from horizontal // to vertical orientation and back // =========================================================== @Override protected void onDestroy() { super.onDestroy(); } // =========================================================== // Save and Restore UI states // =========================================================== @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); } protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); } // =========================================================== // Main Activity methods // =========================================================== public void generateMyGallery() { MyService cs = new MyService(this); domain = cs.getDomainList(); // Add the new_image drawable to the ArrayList Domain d = new Domain(); d.photoLocation = "drawable"; d.photoName = "new_image"; d.extra1 = "no_text"; d.extra2 = "no_text"; domain.add(0, d); myImageAdapter = new MyImageAdapter(this, R.layout.text_overlay_image_view, domain); /* Find the gallery defined in the main.xml */ Gallery g = (Gallery) findViewById(R.id.gallery); g.setSpacing(10); /* Apply a new (custom) ImageAdapter to it. */ g.setAdapter(myImageAdapter); g.setSelection(1); } private void setButtonFriendsClickListener() { Button clickButton = (Button)findViewById(R.id.button_friends_list); clickButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { setContentView(R.layout.friends_list); Intent myIntent = new Intent(v.getContext(), FriendsListActivity.class); startActivity(myIntent); } }); } private void setButtonCameraClickListener() { Button clickButton = (Button)findViewById(R.id.button_take_picture); clickButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { setContentView(R.layout.take_picture); Intent myIntent = new Intent(v.getContext(), TakePictureActivity.class); startActivity(myIntent); } }); } private void setButtonPreferencesClickListener() { Button clickButton = (Button)findViewById(R.id.button_preferences); clickButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent myIntent = new Intent(v.getContext(), MyPreferencesActivity.class); startActivity(myIntent); } }); } }; Anyone has an idea why the App crashes. Any help is much appreciated. I did find out that, when I finish() the MAIN activity when I start the FriendListActivity and restart the MAIN activity when closing the FriendListActivity, that the crash does not occur. However, this basically restarts the App and that is not the intention. Thanks all, I got the problem solved. This is what I did. . When moving all gallery related actions to the onCreate, the creash didn't happen anymore. But then after returning to the MAIN activity, the activity wasn't shown. . I then moved all the onCreate (except the super), the generateGallery, and the onStart() to the onResume. Now it works fine!

    Read the article

  • using Unity Android In a sub view and add actionbar and style

    - by aeroxr1
    I exported a simple animation from Unity3D (version 4.5) in android project. With eclipse I modified the manifest and added another activity. In this activity I put a button that it makes start the animation,and this is the result. The action bar appear in the main activity but it doesn't in the unity's activity :( How can I add the action bar and the style of the first activity to unity's animation activity ? This is the unity's activity's code : package com.rabidgremlin.tut.redcube; import android.app.NativeActivity; import android.content.res.Configuration; import android.graphics.PixelFormat; import android.os.Bundle; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import com.unity3d.player.UnityPlayer; public class UnityPlayerNativeActivity extends NativeActivity { protected UnityPlayer mUnityPlayer; // don't change the name of this variable; referenced from native code // Setup activity layout @Override protected void onCreate (Bundle savedInstanceState) { //requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); getWindow().takeSurface(null); //setTheme(android.R.style.Theme_NoTitleBar_Fullscreen); getWindow().setFormat(PixelFormat.RGB_565); mUnityPlayer = new UnityPlayer(this); /*if (mUnityPlayer.getSettings ().getBoolean ("hide_status_bar", true)) getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); */ setContentView(mUnityPlayer); mUnityPlayer.requestFocus(); } // Quit Unity @Override protected void onDestroy () { mUnityPlayer.quit(); super.onDestroy(); } // Pause Unity @Override protected void onPause() { super.onPause(); mUnityPlayer.pause(); } // eliminiamo questa onResume() e proviamo a modificare la onResume() // Resume Unity @Override protected void onResume() { super.onResume(); mUnityPlayer.resume(); } // inseriamo qualche modifica qui // This ensures the layout will be correct. @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mUnityPlayer.configurationChanged(newConfig); } // Notify Unity of the focus change. @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); mUnityPlayer.windowFocusChanged(hasFocus); } // For some reason the multiple keyevent type is not supported by the ndk. // Force event injection by overriding dispatchKeyEvent(). @Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_MULTIPLE) return mUnityPlayer.injectEvent(event); return super.dispatchKeyEvent(event); } // Pass any events not handled by (unfocused) views straight to UnityPlayer @Override public boolean onKeyUp(int keyCode, KeyEvent event) { return mUnityPlayer.injectEvent(event); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { return mUnityPlayer.injectEvent(event); } @Override public boolean onTouchEvent(MotionEvent event) { return mUnityPlayer.injectEvent(event); } /*API12*/ public boolean onGenericMotionEvent(MotionEvent event) { return mUnityPlayer.injectEvent(event); } } And this is the AndroidManifest.xml android:versionCode="1" android:versionName="1.0" > <!-- android:theme="@android:style/Theme.NoTitleBar"--> <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:xlargeScreens="true" /> <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:theme="@android:style/Theme.Holo.Light" > <activity android:name="com.rabidgremlin.tut.redcube.UnityPlayerNativeActivity" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale" android:label="@string/app_name" android:screenOrientation="portrait" > <!--android:launchMode="singleTask"--> <meta-data android:name="unityplayer.UnityActivity" android:value="true" /> <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" /> </activity> <activity android:name="com.rabidgremlin.tut.redcube.MainActivity" android:label="@string/title_activity_main" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="17" android:targetSdkVersion="19" /> <uses-feature android:glEsVersion="0x00020000" /> </manifest>

    Read the article

  • Android: Using onStart() method in Bluetooth application

    - by Nii
    Hello, I am getting a nullpointer exception when my onStart() method is called. Here is the breakdown of my Android app: Opening the app brings a user to the homescreen: The user is then presented with the first 6 icons to choose from. When the user presses the "Sugar" icon it takes them to the SugarTabActivity. The SugarTabActivity is a Tabbed layout with two tabs. I'm concerned with the first tab. The first tab calls the getDefaultAdapter() method in its onCreate() method. Once it calls this, it checks if the bluetooth adapter is null on the phone, and if its null it shows a toast saying "Bluetooth is not available". This works just fine. Then I call the onStart() method. In the onStart() method I check if bluetooth is enabled, and if it isnt, then I start a new activity from the BluetoothAdapter enable bluetooth intent; otherwise, I start my bluetooth service. The exact error I'm getting is 04-19 00:44:45.674: ERROR/AndroidRuntime(225): Caused by: java.lang.NullPointerException 04-19 00:44:45.674: ERROR/AndroidRuntime(225): at com.nii.glucose.Glucose.onStart(Glucose.java:313). Heading Override public void onCreate(Bundle icicle) { super.onCreate(icicle); if(D) Log.d(TAG, "+++ ON CREATE +++"); setContentView(R.layout.glucose_layout); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if(mBluetoothAdapter==null){ Toast.makeText(this, "Bluetooth not available", Toast.LENGTH_LONG).show(); //finish(); return; } } Override public void onStart() { super.onStart(); if(D) Log.e(TAG, "++ ON START ++"); // If BT is not on, request that it be enabled. // setupChat() will then be called during onActivityResult if (!mBluetoothAdapter.isEnabled()) { Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); // Otherwise, setup the chat session } else { if (mGlucoseService == null) mGlucoseService = new BluetoothService(this, mHandler); } } @Override public synchronized void onResume(){ super.onResume(); if(D) Log.e(TAG,"==== ON RESUME ======"); // Performing this check in onResume() covers the case in which BT was // not enabled during onStart(), so we were paused to enable it... // onResume() will be called when ACTION_REQUEST_ENABLE activity returns. if (mGlucoseService != null) { // Only if the state is STATE_NONE, do we know that we haven't started already if (mGlucoseService.getState() == BluetoothService.STATE_NONE) { // Start the Bluetooth chat services mGlucoseService.start(); } } } @Override public synchronized void onPause(){ super.onPause(); //isActive.set(false); if(D) Log.e(TAG,"==== ON PAUSE ======"); } @Override public void onDestroy() { super.onDestroy(); // Stop the Bluetooth chat services if (mGlucoseService != null) mGlucoseService.stop(); if(D) Log.e(TAG, "--- ON DESTROY ---"); }

    Read the article

  • Android: How to keep onItemSelected from firing off on a newly instantiated Spinner

    - by Drennen
    I've thought of some less than elegant ways to solve this, but I know I must be missing something. My onItemSelected fires off immediately without any interaction with the user, and this is undesired behavior. I wish for the UI to wait until the user selects something before it does anything. I even tried setting up the listener in the onResume, hoping that would help, but it doesn't. How can I stop this from firing off before the user can touch the control? THANKS public class CMSHome extends Activity { private Spinner spinner; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Heres my spinner /////////////////////////////////////////// spinner = (Spinner) findViewById(R.id.spinner); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( this, R.array.pm_list, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); }; public void onResume() { super.onResume(); spinner.setOnItemSelectedListener(new MyOnItemSelectedListener()); } public class MyOnItemSelectedListener implements OnItemSelectedListener { public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { Intent i = new Intent(CMSHome.this, ListProjects.class); i.putExtra("bEmpID", parent.getItemAtPosition(pos).toString()); startActivity(i); Toast.makeText(parent.getContext(), "The pm is " + parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show(); } public void onNothingSelected(AdapterView parent) { // Do nothing. } } }

    Read the article

  • Problems with Acitivity LifeCycle with VideoView playback.

    - by Alex Volovoy
    Hi all i've ran into another problems with VideoView. Then video is playing, and i put device asleep, using hard button, onPause is called. But it followed by 03-17 11:26:33.779: WARN/ActivityManager(884): Activity pause timeout for HistoryRecord{4359f620 com.package/com.package.VideoViewActivity} And then i have onStart/onResume again and Video starts playing. I've try to move code around onStart/onStop - doesn't seems to make difference. sample code : public class VideoViewActivity extends Activity { private String path = ""; private VideoView mVideoView; private static final String MEDIA_URL = "media_url"; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.videoview); mVideoView = (VideoView)findViewById(R.id.surface_view); path = getIntent().getStringExtra(MEDIA_URL); } @Override public void onResume() { super.onResume(); mVideoView.setVideoPath(path); mVideoView.setMediaController(new MediaController(this)); mVideoView.requestFocus(); mVideoView.start(); } @Override public void onPause() { super.onPause(); mVideoView.stopPlayback(); mVideoView.setMediaController(null); } }

    Read the article

  • using Unity Android In a sub view and add style and actionbar

    - by aeroxr1
    I exported a simple animation from Unity3D (version 4.5) in android project. With eclipse I modified the manifest and added another activity. In this activity I put a button that it makes start the animation,and this is the result. The action bar appear in the main activity but it doesn't in the unity's activity :( This is the unity's activity's code : package com.rabidgremlin.tut.redcube; import android.app.NativeActivity; import android.content.res.Configuration; import android.graphics.PixelFormat; import android.os.Bundle; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import com.unity3d.player.UnityPlayer; public class UnityPlayerNativeActivity extends NativeActivity { protected UnityPlayer mUnityPlayer; // don't change the name of this variable; referenced from native code // Setup activity layout @Override protected void onCreate (Bundle savedInstanceState) { //requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); getWindow().takeSurface(null); //setTheme(android.R.style.Theme_NoTitleBar_Fullscreen); getWindow().setFormat(PixelFormat.RGB_565); mUnityPlayer = new UnityPlayer(this); /*if (mUnityPlayer.getSettings ().getBoolean ("hide_status_bar", true)) getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); */ setContentView(mUnityPlayer); mUnityPlayer.requestFocus(); } // Quit Unity @Override protected void onDestroy () { mUnityPlayer.quit(); super.onDestroy(); } // Pause Unity @Override protected void onPause() { super.onPause(); mUnityPlayer.pause(); } // eliminiamo questa onResume() e proviamo a modificare la onResume() // Resume Unity @Override protected void onResume() { super.onResume(); mUnityPlayer.resume(); } // inseriamo qualche modifica qui // This ensures the layout will be correct. @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mUnityPlayer.configurationChanged(newConfig); } // Notify Unity of the focus change. @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); mUnityPlayer.windowFocusChanged(hasFocus); } // For some reason the multiple keyevent type is not supported by the ndk. // Force event injection by overriding dispatchKeyEvent(). @Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_MULTIPLE) return mUnityPlayer.injectEvent(event); return super.dispatchKeyEvent(event); } // Pass any events not handled by (unfocused) views straight to UnityPlayer @Override public boolean onKeyUp(int keyCode, KeyEvent event) { return mUnityPlayer.injectEvent(event); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { return mUnityPlayer.injectEvent(event); } @Override public boolean onTouchEvent(MotionEvent event) { return mUnityPlayer.injectEvent(event); } /*API12*/ public boolean onGenericMotionEvent(MotionEvent event) { return mUnityPlayer.injectEvent(event); } } How can I add the action bar and the style of the first activity to unity's animation activity ?

    Read the article

  • How to put Listview items into String Array?

    - by user2851687
    Im developing an app and as the title says how to put items of listview into String array, not string array to listview but listview to string array. I've been searching for this but what I only found is putting String array items into listview. Please help me thank you in advance. To clarify this thread, the question is how to put listview items into String array. Thanks. :D Codes public class DailyPlanTab extends Activity implements OnItemClickListener { ListView dailyPlanList; ArrayList<DailyManager> taskList = new ArrayList<DailyManager>(); DatabaseDailyPlan db; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.dailyplan_layout); dailyPlanList = (ListView) findViewById(R.id.lvDailyPlanList); dailyPlanList.setOnItemClickListener(this); ImageView add = (ImageView) findViewById(R.id.ivDailyPlanAdd); add.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent newDailyIntent = new Intent(getApplicationContext(), NewDailyPlan.class); startActivity(newDailyIntent); } }); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); taskList.clear(); db = new DatabaseDailyPlan(getApplicationContext()); db.getWritableDatabase(); ArrayList<DailyManager> tempList = db.getTask(); for (int i = 0; i < tempList.size(); i++) { String getTask = tempList.get(i).getDaily_name(); String getDate = tempList.get(i).getDaily_date(); int getId = tempList.get(i).getDaily_id(); DailyManager dm = new DailyManager(); dm.setDaily_name(getTask); dm.setDaily_date(getDate); dm.setDaily_id(getId); taskList.add(dm); } dailyPlanList.setAdapter(new ListAdapter(this)); // db.close(); } public class ListAdapter extends BaseAdapter { LayoutInflater inflater; ViewHolder viewHolder; public ListAdapter(Context c) { // TODO Auto-generated constructor stub inflater = LayoutInflater.from(c); } @Override public int getCount() { // TODO Auto-generated method stub return taskList.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return position; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub if (convertView == null) { convertView = inflater.inflate(R.layout.row_checklist_item, null); viewHolder = new ViewHolder(); viewHolder.taskTitle = (TextView) convertView .findViewById(R.id.tvCheckListItem); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } viewHolder.taskTitle.setText("" + taskList.get(position).getDaily_name()); return convertView; } } public class ViewHolder { TextView taskTitle, taskDate; } @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { // TODO Auto-generated method stub int taskId = taskList.get(position).getDaily_id(); String taskName = taskList.get(position).getDaily_name(); String taskDate = taskList.get(position).getDaily_date(); Intent newPlan = new Intent(getApplicationContext(), DailyPlan.class); newPlan.putExtra("task_id", taskId); newPlan.putExtra("task_name", taskName); startActivity(newPlan); } next is the information of the item inside the listview public class DailyPlan extends Activity implements OnItemClickListener { final ArrayList<DailyManager> savedItems = new ArrayList<DailyManager>(); ListView checkList; Boolean nextItem = false; TempManager tm; DatabaseTemp dbTemp; Intent i; int taskId = -1; String taskName = " ", taskDate = null; DatabaseDailyPlan db; DailyManager dm; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.saved_dailyplan); checkList = (ListView) findViewById(R.id.lvCheckList); // checkList.setOnItemClickListener(this); try { i = getIntent(); taskId = i.getExtras().getInt("task_id"); taskName = i.getExtras().getString("task_name"); Toast.makeText(getApplicationContext(), "From new id is" + taskId, 5000).show(); } catch (Exception e) { } Button addList = (Button) findViewById(R.id.bAddList); addList.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // openDialog("", false, -1); } }); if (nextItem) { // openDialog("", false, -1); } } public void refresh() { DailyPlan.this.onResume(); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); savedItems.clear(); dbTemp = new DatabaseTemp(getApplicationContext()); dbTemp.getWritableDatabase(); db = new DatabaseDailyPlan(getApplicationContext()); db.getWritableDatabase(); if (taskId != -1) { // / For Load ArrayList<DailyManager> savedList = db.getList(taskId); for (int i = 0; i < savedList.size(); i++) { String savedListItems = savedList.get(i).getDaily_list(); String savedListTitle = savedList.get(i).getDaily_name(); String savedListDate = savedList.get(i).getDaily_date(); int savedListId = savedList.get(i).getDaily_id(); DailyManager dm = new DailyManager(); dm.setDaily_list(savedListItems); dm.setDaily_name(savedListTitle); dm.setDaily_date(savedListDate); dm.setDaily_id(savedListId); savedItems.add(dm); } } else { // / For New } checkList.setAdapter(new ListAdapter(this)); } public class ListAdapter extends BaseAdapter { LayoutInflater inflater; ViewHolder viewHolder; public ListAdapter(Context c) { // TODO Auto-generated constructor stub inflater = LayoutInflater.from(c); } @Override public int getCount() { // TODO Auto-generated method stub return savedItems.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return position; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub if (convertView == null) { convertView = inflater.inflate(R.layout.row_checklist_item, null); viewHolder = new ViewHolder(); viewHolder.checkListItem = (TextView) convertView .findViewById(R.id.tvCheckListItem); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } viewHolder.checkListItem.setText(savedItems.get(position) .getDaily_list() + position); final int temp = position; return convertView; } } private class ViewHolder { TextView checkListItem; } @Override public void onItemClick(AdapterView<?> arg0, View arg1, int item, long arg3) { // TODO Auto-generated method stub // openDialog(savedItems.get(item).getDaily_name(), true, // savedItems.get(item).getDaily_id()); } }

    Read the article

  • How to label a cuboid?

    - by usha
    Hi this is how my 3dcuboid looks, I have attached the complete code. I want to label this cuboid using different names across sides, how is this possible using opengl on android? public class MyGLRenderer implements Renderer { Context context; Cuboid rect; private float mCubeRotation; // private static float angleCube = 0; // Rotational angle in degree for cube (NEW) // private static float speedCube = -1.5f; // Rotational speed for cube (NEW) public MyGLRenderer(Context context) { rect = new Cuboid(); this.context = context; } public void onDrawFrame(GL10 gl) { // TODO Auto-generated method stub gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); // Reset the model-view matrix gl.glTranslatef(0.2f, 0.0f, -8.0f); // Translate right and into the screen gl.glScalef(0.8f, 0.8f, 0.8f); // Scale down (NEW) gl.glRotatef(mCubeRotation, 1.0f, 1.0f, 1.0f); // gl.glRotatef(angleCube, 1.0f, 1.0f, 1.0f); // rotate about the axis (1,1,1) (NEW) rect.draw(gl); mCubeRotation -= 0.15f; //angleCube += speedCube; } public void onSurfaceChanged(GL10 gl, int width, int height) { // TODO Auto-generated method stub if (height == 0) height = 1; // To prevent divide by zero float aspect = (float)width / height; // Set the viewport (display area) to cover the entire window gl.glViewport(0, 0, width, height); // Setup perspective projection, with aspect ratio matches viewport gl.glMatrixMode(GL10.GL_PROJECTION); // Select projection matrix gl.glLoadIdentity(); // Reset projection matrix // Use perspective projection GLU.gluPerspective(gl, 45, aspect, 0.1f, 100.f); gl.glMatrixMode(GL10.GL_MODELVIEW); // Select model-view matrix gl.glLoadIdentity(); // Reset } public void onSurfaceCreated(GL10 gl, EGLConfig config) { // TODO Auto-generated method stub gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set color's clear-value to black gl.glClearDepthf(1.0f); // Set depth's clear-value to farthest gl.glEnable(GL10.GL_DEPTH_TEST); // Enables depth-buffer for hidden surface removal gl.glDepthFunc(GL10.GL_LEQUAL); // The type of depth testing to do gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST); // nice perspective view gl.glShadeModel(GL10.GL_SMOOTH); // Enable smooth shading of color gl.glDisable(GL10.GL_DITHER); // Disable dithering for better performance }} public class Cuboid{ private FloatBuffer mVertexBuffer; private FloatBuffer mColorBuffer; private ByteBuffer mIndexBuffer; private float vertices[] = { //width,height,depth -2.5f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -2.5f, 1.0f, -1.0f, -2.5f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -2.5f, 1.0f, 1.0f }; private float colors[] = { // R,G,B,A COLOR 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.5f, 0.0f, 1.0f, 1.0f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f }; private byte indices[] = { // VERTEX 0,1,2,3,4,5,6,7 REPRESENTATION FOR FACES 0, 4, 5, 0, 5, 1, 1, 5, 6, 1, 6, 2, 2, 6, 7, 2, 7, 3, 3, 7, 4, 3, 4, 0, 4, 7, 6, 4, 6, 5, 3, 0, 1, 3, 1, 2 }; public Cuboid() { ByteBuffer byteBuf = ByteBuffer.allocateDirect(vertices.length * 4); byteBuf.order(ByteOrder.nativeOrder()); mVertexBuffer = byteBuf.asFloatBuffer(); mVertexBuffer.put(vertices); mVertexBuffer.position(0); byteBuf = ByteBuffer.allocateDirect(colors.length * 4); byteBuf.order(ByteOrder.nativeOrder()); mColorBuffer = byteBuf.asFloatBuffer(); mColorBuffer.put(colors); mColorBuffer.position(0); mIndexBuffer = ByteBuffer.allocateDirect(indices.length); mIndexBuffer.put(indices); mIndexBuffer.position(0); } public void draw(GL10 gl) { gl.glFrontFace(GL10.GL_CW); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer); gl.glColorPointer(4, GL10.GL_FLOAT, 0, mColorBuffer); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_COLOR_ARRAY); gl.glDrawElements(GL10.GL_TRIANGLES, 36, GL10.GL_UNSIGNED_BYTE, mIndexBuffer); gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); gl.glDisableClientState(GL10.GL_COLOR_ARRAY); } } public class Draw3drect extends Activity { private GLSurfaceView glView; // Use GLSurfaceView // Call back when the activity is started, to initialize the view @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); glView = new GLSurfaceView(this); // Allocate a GLSurfaceView glView.setRenderer(new MyGLRenderer(this)); // Use a custom renderer this.setContentView(glView); // This activity sets to GLSurfaceView } // Call back when the activity is going into the background @Override protected void onPause() { super.onPause(); glView.onPause(); } // Call back after onPause() @Override protected void onResume() { super.onResume(); glView.onResume(); } }

    Read the article

1 2 3 4 5  | Next Page >