有没有办法知道应用程序是否通过本地通知变为活动状态?
我知道有一种方法来测试,如果应用程序被启动从本地通知提醒; 但如果只是坐在那里的背景,并收到通知?
当应用程序变为活动状态时,我需要运行不同的代码:
有办法吗?
一个iPhone应用程序,通过TCP连接到远程服务器.使用场景是:
假设如果应用程序30分钟内没有向服务器发送数据,服务器将关闭连接.即使用户什么也不做,我想让连接保持120分钟.
案例1:如果应用程序在前台,我可以使用计时器向服务器发送一些无用数据.没问题.
案例2:如果用户按下主页并且应用程序转到后台,我该怎么办?我不想表现出警告或某些事情来打断用户(他不在或正在玩游戏).我只想让连接保持更长时间,当用户回到应用程序时,他发现连接仍然存在并且对此感到满意.
我已阅读有关iphone API的后台执行,多任务处理和本地通知的文档.我不确定能否达到案例2.
仅使用合法的API,不进行越狱.
我有一个照片类型(不是风景)背景图像,宽度为979像素,高度为1200像素.我想将它设置为向左浮动并显示100%全图像高度固定,而无需向上/向下滚动(无论内容长度如何).
这是我的CSS代码,但它不起作用:
img, media {
max-width: 100%;
}
body {
background-color: white;
background-image: url('../images/bg-image.jpg');
background-size: auto 100%;
background-repeat: no-repeat;
background-position: left top;
}
Run Code Online (Sandbox Code Playgroud) 我有一个非常奇怪的问题,我实施了:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler
Run Code Online (Sandbox Code Playgroud)
用于静音远程推送通知.当应用程序处于后台并连接到Xcode时,它非常适用.当我拔下任何iOS设备并运行应用程序时,请移至后台并发送远程通知,didReceiveRemoteNotification:fetchCompletionHandler
而不是被调用.
我的代码如下:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSInteger pushCode = [userInfo[@"pushCode"] integerValue];
NSLog(@"Silent Push Code Notification: %i", pushCode);
NSDictionary *aps = userInfo[@"aps"];
NSString *alertMessage = aps[@"alert"];
if (pushCode == kPushCodeShowText) {
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = [NSDate date];
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertBody = alertMessage;
localNotif.alertAction = @"OK";
localNotif.soundName = @"sonar.aiff";
// localNotif.applicationIconBadgeNumber = 0;
localNotif.userInfo = nil;
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotif];
UILocalNotification *clearNotification …
Run Code Online (Sandbox Code Playgroud) debugging background objective-c apple-push-notifications ios
IntentService
即使应用程序被杀,我也想继续在后台运行.并且被"杀死"我的意思是按住主页按钮很长时间 - > 查看所有正在运行的应用程序 - >将我的应用程序放在一边 - > 应用程序被杀或按下后退按钮很长时间 - > 应用程序被杀
我的代码如下.在我的MainActivity中:
Intent intent = new Intent(this, MyService.class);
this.startService(intent);
Run Code Online (Sandbox Code Playgroud)
在我的MyService中:
public class MyService extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
System.out.println("MyService started");
run();
}
private void run() {
while (true){
System.out.println("MyService still running");
doSomething();
waitSomeTime();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我看到应用程序打开时服务正在运行.当我通过主页按钮最小化应用程序时,它仍在运行.当我通过后退按钮关闭应用程序时,它仍在运行.但如果我如上所述杀死它,它就会停止.我该如何解决这个问题?
我目前正在做一个视差网站主题.对于某些'div'和'section,需要将背景图像附加为固定的,以避免jquery沉迷于所有内容.问题是任何动画项目下方标签的背景图像在转换完成时消失,仅在Google Chrome上.补救?
我正在建立一个习惯DialogFragment
.对话框布局设置为my_dialog.xml
,但如何修改对话框周围的颜色(透明灰色)?
my_dialog.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" >
<TextView
android:id="@+id/hello"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@android:color/holo_orange_light"
android:gravity="center"
android:text="hello" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
MyDialogFragment.java
public class MyDialogFragment extends DialogFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.my_dialog, container);
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
return view;
}
}
Run Code Online (Sandbox Code Playgroud) 我的意思是在完全背景下工作,例如,即使屏幕关闭,应用程序正在运行,并可以发送声音通知.
我的应用用于观看价格变化.价格变化时会发出声音警报.
那么,答案应该是肯定还是否定?谢谢.
当我将我的应用程序推送到后台,并做一些其他的东西,如whatsapp或短信,onResume它很好.
但是我最近发现,当我的应用程序在后台打开/启动Facebook应用程序时,我不知道会发生什么......
但是onResume,应用程序行为异常......
不要做它需要做的事情,但是当我回到主页并回来它工作正常请帮助我...如何解决它?
包含所有消息的Logcat(不带过滤器)
10-15 12:53:59.899: I/Adreno-EGL(32033): Remote Branch: quic/LNX.LA.3.5.1_RB1.1
10-15 12:53:59.899: I/Adreno-EGL(32033): Local Patches: NONE
10-15 12:53:59.899: I/Adreno-EGL(32033): Reconstruct Branch: AU_LINUX_ANDROID_LNX.LA.3.5.1_RB1.04.04.02.048.018 + f2fd134 + NOTHING
10-15 12:53:59.924: D/OpenGLRenderer(32033): Enabling debug mode 0
10-15 12:54:00.000: V/AlarmManager(7677): sending alarm Alarm{42cfa490 type 3 android}
10-15 12:54:00.110: I/ActivityManager(7677): Displayed uk.org.humanfocus.hfi/.EvaluateTrainingActivity: +838ms
10-15 12:54:00.114: D/WifiStateMachine(7677): handleMessage: E msg.what=151572
10-15 12:54:00.114: D/WifiStateMachine(7677): processMsg: ConnectedState
10-15 12:54:00.114: D/WifiStateMachine(7677): processMsg: L2ConnectedState
10-15 12:54:02.258: V/AlarmManager(7677): sending alarm Alarm{42ebd600 type 1 com.facebook.katana}
10-15 12:54:02.274: V/AlarmManager(7677): sending alarm Alarm{42ec0ff0 …
Run Code Online (Sandbox Code Playgroud) android background onresume android-lifecycle android-activity
我的布局包含一些文本字段,并且背景图像显示在我的活动顶部.我希望背景图像可以缩放以包装内容(不关心宽高比).但是,图像大于内容,因此布局反而包裹背景图像.这是我的原始代码:
<RelativeLayout
android:layout_width="fill_parent"
android:id="@+id/HeaderList"
android:layout_gravity="top"
android:layout_height="wrap_content"
android:background="@drawable/header">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/NameText"
android:text="Jhn Doe"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingLeft="4dp"
android:paddingTop="4dp"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#FFFFFF"
android:layout_alignParentLeft="true"
android:id="@+id/HoursText"
android:text="170 hours"
android:textSize="23sp"
android:layout_below="@+id/NameText"
android:paddingLeft="4dp"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
在搜索了其他一些问题后,我发现了这两个问题:
基于此,我创建了一个带有ImageView的FrameLayout,显示背景.不幸的是,我仍然无法让它工作.我想要的背景图像的高度缩小/扩大W /文观点的大小,但与FrameLayout里,该ImageView的适合的大小的它的父,我无法找到一个办法让母公司适合文本视图布局的大小.这是我更新的代码:
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView android:src="@drawable/header"
android:layout_width="fill_parent"
android:scaleType="fitXY"
android:layout_height="fill_parent"
/>
<RelativeLayout
android:layout_width="fill_parent"
android:id="@+id/HeaderList"
android:layout_gravity="top"
android:layout_height="wrap_content"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/NameText"
android:text="John Doe"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingLeft="4dp"
android:paddingTop="4dp"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#FFFFFF"
android:layout_alignParentLeft="true"
android:id="@+id/HoursText"
android:text="170 hours"
android:textSize="23sp"
android:layout_below="@+id/NameText"
android:paddingLeft="4dp"
/>
</RelativeLayout> …
Run Code Online (Sandbox Code Playgroud) android background android-linearlayout android-relativelayout android-framelayout