当应用变为活动状态时重新加载数据

时间:2015-08-29 23:15:56

标签: java android

如何在应用程序变为活动状态或成为前台时重新加载所有数据?在iOS上有这样的东西:

[[NSNotificationCenter defaultCenter]addObserver:self
                                            selector:@selector(viewDidLoad)
                                            name:UIApplicationDidBecomeActiveNotification
                                            object:nil];

1 个答案:

答案 0 :(得分:0)

1)在Android中,您还无法清楚地了解整个应用程序何时具有前瞻性。虽然有一些非常好的黑客。看看这个Stack Overflow答案。但要注意,你应该使用onStart和onStop而不是onResume和onPause,如答案所指定的那样。

special meaning

2)你可以告诉特定活动(通常是应用程序中的单个页面)何时在前台。我假设通过重新加载数据,您的意思是您想从本地数据库重新加载数据或从服务器获取数据。在任何一种情况下,您都可以通过覆盖Activity的onResume()方法来完成此操作。

-------------- Clean: DebugWin64 in infiltrator (compiler: MinGW)---------------

Cleaned "infiltrator - DebugWin64"

-------------- Build: DebugWin64 in infiltrator (compiler: MinGW)---------------

i686-w64-mingw32-g++ -Wall -std=c++11 -Wall -g -m64 -pthread -I/usr/include/gtkmm-3.0 -I/usr/lib/x86_64-linux-gnu/gtkmm-3.0/include -I/usr/include/atkmm-1.6 -I/usr/include/gtk-3.0/unix-print -I/usr/include/gdkmm-3.0 -I/usr/lib/x86_64-linux-gnu/gdkmm-3.0/include -I/usr/include/giomm-2.4 -I/usr/lib/x86_64-linux-gnu/giomm-2.4/include -I/usr/include/pangomm-1.4 -I/usr/lib/x86_64-linux-gnu/pangomm-1.4/include -I/usr/include/glibmm-2.4 -I/usr/lib/x86_64-linux-gnu/glibmm-2.4/include -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/mirclient -I/usr/include/mircommon -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/cairomm-1.0 -I/usr/lib/x86_64-linux-gnu/cairomm-1.0/include -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/sigc++-2.0 -I/usr/lib/x86_64-linux-gnu/sigc++-2.0/include -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/x86_64-linux-gnu -v -DWINVER=0x0400 -D__WIN95__ -D__GNUWIN32__ -DSTRICT -DHAVE_W32API_H -D__WXMSW__ -D__WINDOWS__ -DWINVER=0x0400 -D__WIN95__ -D__GNUWIN32__ -DSTRICT -DHAVE_W32API_H -D__WXMSW__ -D__WINDOWS__ -Iinclude -I/usr/x86_64-w64-mingw32/include -I/usr/x86_64-w64-mingw32/include -c /home/jason/Code/Repositories/infiltrator-git/main.cpp -o obj/Debug/Winx64/main.o
Using built-in specs.
COLLECT_GCC=i686-w64-mingw32-g++
Target: i686-w64-mingw32
Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++ --enable-lto --with-plugin-ld --enable-threads=win32 --program-suffix=-win32 --program-prefix=i686-w64-mingw32- --target=i686-w64-mingw32 --with-as=/usr/bin/i686-w64-mingw32-as --with-ld=/usr/bin/i686-w64-mingw32-ld
Thread model: win32
gcc version 4.9.2 (GCC) 
COLLECT_GCC_OPTIONS='-std=c++11' '-Wall' '-g' '-m64' '-pthread' '-I' '/usr/include/gtkmm-3.0' '-I' '/usr/lib/x86_64-linux-gnu/gtkmm-3.0/include' '-I' '/usr/include/atkmm-1.6' '-I' '/usr/include/gtk-3.0/unix-print' '-I' '/usr/include/gdkmm-3.0' '-I' '/usr/lib/x86_64-linux-gnu/gdkmm-3.0/include' '-I' '/usr/include/giomm-2.4' '-I' '/usr/lib/x86_64-linux-gnu/giomm-2.4/include' '-I' '/usr/include/pangomm-1.4' '-I' '/usr/lib/x86_64-linux-gnu/pangomm-1.4/include' '-I' '/usr/include/glibmm-2.4' '-I' '/usr/lib/x86_64-linux-gnu/glibmm-2.4/include' '-I' '/usr/include/gtk-3.0' '-I' '/usr/include/at-spi2-atk/2.0' '-I' '/usr/include/at-spi-2.0' '-I' '/usr/include/dbus-1.0' '-I' '/usr/lib/x86_64-linux-gnu/dbus-1.0/include' '-I' '/usr/include/gtk-3.0' '-I' '/usr/include/gio-unix-2.0/' '-I' '/usr/include/mirclient' '-I' '/usr/include/mircommon' '-I' '/usr/include/cairo' '-I' '/usr/include/pango-1.0' '-I' '/usr/include/harfbuzz' '-I' '/usr/include/pango-1.0' '-I' '/usr/include/atk-1.0' '-I' '/usr/include/cairo' '-I' '/usr/include/cairomm-1.0' '-I' '/usr/lib/x86_64-linux-gnu/cairomm-1.0/include' '-I' '/usr/include/cairo' '-I' '/usr/include/pixman-1' '-I' '/usr/include/freetype2' '-I' '/usr/include/libpng12' '-I' '/usr/include/sigc++-2.0' '-I' '/usr/lib/x86_64-linux-gnu/sigc++-2.0/include' '-I' '/usr/include/gdk-pixbuf-2.0' '-I' '/usr/include/libpng12' '-I' '/usr/include/glib-2.0' '-I' '/usr/lib/x86_64-linux-gnu/glib-2.0/include' '-I' '/usr/include/x86_64-linux-gnu' '-v' '-D' 'WINVER=0x0400' '-D' '__WIN95__' '-D' '__GNUWIN32__' '-D' 'STRICT' '-D' 'HAVE_W32API_H' '-D' '__WXMSW__' '-D' '__WINDOWS__' '-D' 'WINVER=0x0400' '-D' '__WIN95__' '-D' '__GNUWIN32__' '-D' 'STRICT' '-D' 'HAVE_W32API_H' '-D' '__WXMSW__' '-D' '__WINDOWS__' '-I' 'include' '-I' '/usr/x86_64-w64-mingw32/include' '-I' '/usr/x86_64-w64-mingw32/include' '-c' '-o' 'obj/Debug/Winx64/main.o' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/i686-w64-mingw32/4.9-win32/cc1plus -quiet -v -I /usr/include/gtkmm-3.0 -I /usr/lib/x86_64-linux-gnu/gtkmm-3.0/include -I /usr/include/atkmm-1.6 -I /usr/include/gtk-3.0/unix-print -I /usr/include/gdkmm-3.0 -I /usr/lib/x86_64-linux-gnu/gdkmm-3.0/include -I /usr/include/giomm-2.4 -I /usr/lib/x86_64-linux-gnu/giomm-2.4/include -I /usr/include/pangomm-1.4 -I /usr/lib/x86_64-linux-gnu/pangomm-1.4/include -I /usr/include/glibmm-2.4 -I /usr/lib/x86_64-linux-gnu/glibmm-2.4/include -I /usr/include/gtk-3.0 -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -I /usr/include/gtk-3.0 -I /usr/include/gio-unix-2.0/ -I /usr/include/mirclient -I /usr/include/mircommon -I /usr/include/cairo -I /usr/include/pango-1.0 -I /usr/include/harfbuzz -I /usr/include/pango-1.0 -I /usr/include/atk-1.0 -I /usr/include/cairo -I /usr/include/cairomm-1.0 -I /usr/lib/x86_64-linux-gnu/cairomm-1.0/include -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/freetype2 -I /usr/include/libpng12 -I /usr/include/sigc++-2.0 -I /usr/lib/x86_64-linux-gnu/sigc++-2.0/include -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/libpng12 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/x86_64-linux-gnu -I include -I /usr/x86_64-w64-mingw32/include -I /usr/x86_64-w64-mingw32/include -imultilib . -D_REENTRANT -U_REENTRANT -D WINVER=0x0400 -D __WIN95__ -D __GNUWIN32__ -D STRICT -D HAVE_W32API_H -D __WXMSW__ -D __WINDOWS__ -D WINVER=0x0400 -D __WIN95__ -D __GNUWIN32__ -D STRICT -D HAVE_W32API_H -D __WXMSW__ -D __WINDOWS__ /home/jason/Code/Repositories/infiltrator-git/main.cpp -quiet -dumpbase main.cpp -m64 -mtune=generic -march=x86-64 -auxbase-strip obj/Debug/Winx64/main.o -g -Wall -std=c++11 -version -o /tmp/cciELoJN.s
GNU C++ (GCC) version 4.9.2 (i686-w64-mingw32)
    compiled by GNU C version 4.9.2, GMP version 6.0.0, MPFR version 3.1.2-p11, MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/lib/gcc/i686-w64-mingw32/4.9-win32/../../../../i686-w64-mingw32/sys-include"
ignoring duplicate directory "/usr/include/gtk-3.0"
ignoring duplicate directory "/usr/include/pango-1.0"
ignoring duplicate directory "/usr/include/cairo"
ignoring duplicate directory "/usr/include/cairo"
ignoring duplicate directory "/usr/include/libpng12"
ignoring duplicate directory "/usr/x86_64-w64-mingw32/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/gtkmm-3.0
 /usr/lib/x86_64-linux-gnu/gtkmm-3.0/include
 /usr/include/atkmm-1.6
 /usr/include/gtk-3.0/unix-print
 /usr/include/gdkmm-3.0
 /usr/lib/x86_64-linux-gnu/gdkmm-3.0/include
 /usr/include/giomm-2.4
 /usr/lib/x86_64-linux-gnu/giomm-2.4/include
 /usr/include/pangomm-1.4
 /usr/lib/x86_64-linux-gnu/pangomm-1.4/include
 /usr/include/glibmm-2.4
 /usr/lib/x86_64-linux-gnu/glibmm-2.4/include
 /usr/include/gtk-3.0
 /usr/include/at-spi2-atk/2.0
 /usr/include/at-spi-2.0
 /usr/include/dbus-1.0
 /usr/lib/x86_64-linux-gnu/dbus-1.0/include
 /usr/include/gio-unix-2.0/
 /usr/include/mirclient
 /usr/include/mircommon
 /usr/include/cairo
 /usr/include/pango-1.0
 /usr/include/harfbuzz
 /usr/include/atk-1.0
 /usr/include/cairomm-1.0
 /usr/lib/x86_64-linux-gnu/cairomm-1.0/include
 /usr/include/pixman-1
 /usr/include/freetype2
 /usr/include/libpng12
 /usr/include/sigc++-2.0
 /usr/lib/x86_64-linux-gnu/sigc++-2.0/include
 /usr/include/gdk-pixbuf-2.0
 /usr/include/glib-2.0
 /usr/lib/x86_64-linux-gnu/glib-2.0/include
 /usr/include/x86_64-linux-gnu
 include
 /usr/x86_64-w64-mingw32/include
 /usr/lib/gcc/i686-w64-mingw32/4.9-win32/include/c++
 /usr/lib/gcc/i686-w64-mingw32/4.9-win32/include/c++/i686-w64-mingw32/.
 /usr/lib/gcc/i686-w64-mingw32/4.9-win32/include/c++/backward
 /usr/lib/gcc/i686-w64-mingw32/4.9-win32/include
 /usr/lib/gcc/i686-w64-mingw32/4.9-win32/include-fixed
 /usr/lib/gcc/i686-w64-mingw32/4.9-win32/../../../../i686-w64-mingw32/include
End of search list.
/home/jason/Code/Repositories/infiltrator-git/main.cpp:1:0: sorry, unimplemented: 64-bit mode not compiled in
 #include <glibmm.h>
 ^
GNU C++ (GCC) version 4.9.2 (i686-w64-mingw32)
    compiled by GNU C version 4.9.2, GMP version 6.0.0, MPFR version 3.1.2-p11, MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))